[plt-scheme] auxiliary macros
>
> 2. How can I use the macro system to eliminate the 'yield-name' part
> of the macro?
One solution that works, but I do have a few problems with it.
I had to break the hygiene, which in this case might not be that bad, but it
is not nice. More worringly for me, I'm not sure why does it really work the
way it works. It is a problem with my understanding of macros, but that
might pass with time =)
What would be a hygienic solution?
===========================
(require (lib "control.ss"))
(define-syntax (make-gen stx)
(syntax-case stx ()
[(mkg (name arg ...) body ...)
(syntax-case (datum->syntax-object (syntax mkg) 'yield) ()
[yield (syntax
(define (name arg ...)
(define (control-state) body ...)
(define (yield value) (control resume-here (set!
control-state resume-here) value))
(lambda () (prompt (control-state)))))])]))
(make-gen (make-step)
(yield 1)
(yield 2)
(yield 3)
'finished)
(define step (make-step))
(step)(step)(step)(step)(step)
===========================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070803/29592dff/attachment.html>