Generators for PLT Scheme

To use this in PLT Scheme, it's probably easiest to grab it from PLaneT. Here's a quick-and-dirty example to show what this does.

(module test-generator mzscheme
  (require (planet "" ("dyoo" "generator.plt" 2 0)))

  (provide nums-from-n)

  ;; produces a generator that starts counting from n.
  (define-generator (nums-from-n n)
    (let loop ((n n))
      (yield n)
      (loop (add1 n))))

  (define nums-from-42 (nums-from-n 42))
  (printf "~a~n" (generator-next nums-from-42))
  (printf "~a~n" (generator-next nums-from-42))
  (printf "~a~n" (generator-next nums-from-42)))

(Thanks to Paste Scheme for making the example code above look pretty.)

All releases

Back to PLT.