<span class="q"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">2. How can I use the macro system to eliminate the 'yield-name' part
<br>of the macro? </blockquote></span><br>One solution that works, but I do have a few problems with it.<br>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 =)
<br><br>What would be a hygienic solution?<br><br>===========================<br>(require (lib "control.ss"))<br><br>(define-syntax (make-gen stx)<br> (syntax-case stx ()<br> [(mkg (name arg ...) body ...)<br>
(syntax-case (datum->syntax-object (syntax mkg) 'yield) ()<br> [yield (syntax<br> (define (name arg ...)<br> (define (control-state) body ...)<br> (define (yield value) (control resume-here (set! control-state resume-here) value))
<br> (lambda () (prompt (control-state)))))])]))<br><br>(make-gen (make-step)<br> (yield 1)<br> (yield 2)<br> (yield 3)<br> 'finished)<br><br>(define step (make-step))
<br><br>(step)(step)(step)(step)(step)<br><br>===========================<br><br>