[plt-scheme] Re: yield-oriented sequence constructor

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Mar 21 23:32:40 EDT 2008

On Mar 21, Doug Orleans wrote:
> Here's a much simpler version of make-yield-sequence, though it
> seems kinda like voodoo to me.  I'm wondering if I can just lift
> this yield to the top level and get rid of the parameter altogether,
> but then how do I install the default behavior in a top-level
> prompt?

Seems like voodoo to me too, but is there really a need for a

BTW, there is a `function-iterator' in Swindle, which sort of
translates to this (modulo the voodooness, so I won't be surprised if
this is doing something horribly wrong):

  (define (iter fun finally)
    (define (yield v) (control k (set! cont (lambda () (k (void)))) v))
    (define (cont) (fun yield) finally)
    (lambda () (prompt (cont))))

Used like this:

  > (define i (iter (lambda (yield) (for-each yield '(1 2 3))) eof))
  > (i)
  > (i)
  > (i)
  > (i)
  > (i)

and do-ized:

  (define (in-yielder f)
    (define end (list 1))
    (define i (iter f end))
    (make-do-sequence (lambda ()
                        (values (lambda (_) (i))
                                void void void
                                (lambda (e) (not (eq? end e)))
  (for/list ([x (in-yielder (lambda (yield)
                              (for-each yield '(1 2 3))))])

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.