[plt-scheme] auxiliary macros

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

Matthias thanks a lot

1. How can I use control.ss so that I don't need two call/cc's to
> implement a switch of control?


something like this?
---------------
(require (lib "control.ss"))

(define-syntax make-gen
  (syntax-rules ()
    [(_ yield-name (name arg ...) body ...)
     (define (name arg ...)
       (define (control-state) body ...)
       (define (yield-name value)
          (control resume-here (set! control-state resume-here) value))
       (lambda () (prompt (control-state))))
       ]))

(make-gen yield (make-step)
  (yield 1)
  (yield 2)
  (yield 3)
  'finished)

(define step (make-step))

(step) (step) (step) (step) (step)


> 2. How can I use the macro system to eliminate the 'yield-name' part
> of the macro?


That's the bit I need to work on, I suppose :)  I'll play with that later
today.

You may also realize that step is a non-re-entrant function. Argh.
> But I didn't choose that part :-)


Yes, it is not. But then again the python/lua equivalents are not really
reentrant either, and I just try to mimic those. At least for now. Turning
this into a 'factory' I think improves somewhat the practicality of the
code.

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

Posted on the users mailing list.