(module in-list racket
  (require racket/unsafe/ops)
  ;; the following code should be equivalent to the code generated by:
  ;; (for: ((i : Natural (in-list '(1 2 3))))
  ;;   (display i))
  (let-values (((pos->vals pos-next init pos-cont? val-cont? all-cont?)
                (let-values (((i) '(1 2 3)))
                  (values unsafe-car unsafe-cdr i
                          (lambda (x) (not (null? x)))
                          (lambda (x) #t)
                          (lambda (x y) #t)))))
    (void)
    ((letrec-values (((for-loop)
                      (#%plain-lambda
                          (fold-var pos)
                        (if (pos-cont? pos)
                            (let-values (((i) (pos->vals pos)))
                              (if (val-cont? i)
                                  (let-values (((fold-var)
                                                (let-values (((fold-var)
                                                              fold-var))
                                                  (let-values ()
                                                    (let-values ()
                                                      (display i))
                                                    (void)))))
                                    (if (all-cont? pos i)
                                        (for-loop fold-var (pos-next pos))
                                        fold-var))
                                  fold-var))
                            fold-var))))
                    for-loop)
     (void)
     init))
  (void))
