[plt-scheme] suggestions on generators.ss

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Thu Apr 6 18:53:09 EDT 2006

Hi everyone,

I've been fiddling around a little more with the generator example from
earlier this week, and have revised it to this:


I was planning to submit this to PLaneT in a bit, as soon as I wrote some
more test cases.  Is there other functionality that people would like with
these things, or any other suggestions?

For example, I added some non-hygienic syntactic sugar:

> (require "generator.ss")
> (define-generator (evens n)
    (let loop ((n n))
      (yield n)
      (loop (+ n 2))))
> (let ((my-generator (evens 10)))
    (list (my-generator) (my-generator) (my-generator)))
(10 12 14)

I know bad things will probably happen if I lexically bind yield:

> (define-generator (evens n)
    (let yield ((n n))
      (yield n)
      (yield (+ n 2))))
> (define f (evens 0))
> (f)
;; hilarity ensues

I think a solution would be to somehow restrict 'yield as a real keyword
in the context of a define-generator (though I'm not quite sure how to do
this yet).  But perhaps the non-hygienic macro is just a bad idea?

Posted on the users mailing list.