[plt-scheme] auxiliary macros

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Aug 2 11:33:18 EDT 2007

I believe what you want is this:

(define-syntax define/y
   (syntax-rules ()
     [(_ yield-name (name arg ...) body ...)
      (define (name arg ...)
        (define (yield-name x)
           (lambda (resume-here)
             (set! name (lambda () (resume-here 'dummy)))
             (exit-with x))))
        (define exit-with #f)
         (lambda (k)
           (set! exit-with k)

(define/y yield (step)
   (yield 1)
   (yield 2)
   (yield 3)

You can now ask yourself two questions on improving this code:

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

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

Depends in which order you want to improve your skills.

;; ---

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

-- Matthias

Posted on the users mailing list.