[plt-scheme] auxiliary macros

From: Vladimir Zlatanov (vlado at dikini.net)
Date: Thu Aug 2 10:53:12 EDT 2007

After reading http://blog.plt-scheme.org/2007/07/control-resumed.html I
decided to look into prompt/control/%/fcontrol and the rest of the goodies
in control.ss

So based on the example from the blog post I did this python like snippet.

================
(require (lib "control.ss"))

(define (make-step)
  (define (body)
    (yield 1)
    (yield 2)
    (yield 3)
    'finished)
  (define (yield value) (control resume-here (set! _body_ resume-here)
value))
  (define (generator) (prompt (body)))
  (generator))
================

I decided to look into turning it into a macro, such that the following ends
up being correct code
==============
(define/y (step)
  (yield 1)
  (yield 2)
  (yield 3)
  'finished)
==============

My problem is that I don't know how to define yield as a macro inside the
define/y scope, since it need to be able to access _body_, which is a
defined in define/y. All I come up with are various non-hygienic (and simply
broken) variations.

Can you point me to some examples doing something similar (and/or relevant
docs).

I know that there is generator.ss in planet, but for me this is a nice
exercise, since I'm trying to build some intuition about scheme macros. I
was avoiding them for too long...

Cheers,
Vlado
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070802/cbe7621e/attachment.html>

Posted on the users mailing list.