[plt-scheme] understanding make-do-sequence

From: Doug Orleans (dougorleans at gmail.com)
Date: Mon Apr 14 16:20:28 EDT 2008

Dave Herman writes:
 > It appears that `make-do-sequence' avoids applying the first procedure 
 > (the pos->element one) if certain other procedures indicate the sequence 
 > is finished. This is important to the client in the case where that 
 > procedure has side effects.
 > [...]
 > This seems pretty subtle. I don't know if a cleaner API is possible, but 
 > it at least bears documenting exactly when the pos->element will and 
 > won't be applied.

Here's my understanding of how the procedures are called:

  (for ((x (make-do-sequence thunk))) stmt)

is equivalent to

  (let-values (((elt next pos pos? elt? more?) (thunk)))
    (let loop ((pos pos))
      (when (pos? pos)
        (let ((x (elt pos)))
          (when (elt? x)
            (when (more? pos elt)
              (loop (next pos))))))))

Is that enough of a spec?

--dougorleans at gmail.com

Posted on the users mailing list.