<br><div class="gmail_quote">On Fri, Jan 16, 2009 at 3:52 PM, Ryan Culpepper <span dir="ltr"><<a href="mailto:ryanc@ccs.neu.edu">ryanc@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
;; the non-working cond-it<br>
(define-syntax (cond-it stx)<br>
(syntax-case stx (else)<br>
((cond-it (else exp exp2 ...))<br>
#'(begin exp exp2 ...))<br>
((cond-it (test? exp exp2 ...))<br>
#'(when-it test? exp exp2 ...))<br>
((cond-it (test? exp exp2 ...) cond1 cond2 ...)<br>
#'(if-it test? (begin exp exp2 ...)<br>
(cond-it cond1 cond2 ...)))))<br>
</blockquote>
<br></div>
When 'cond-it' expands and produces an 'if-it' expression, the 'if-it' is marked by the macro expander as coming from a macro. That means its lexical context is different from the 'it' variables in the branches. That means that the 'it' variable binding produced by 'if-it' does not capture the 'it' references in the branches.<br>
</blockquote><div><br>I see - based on this I tried to see if I can mark `if-it` to be the same lexical context but i get a compiler warning instead... <br><br><div style="margin-left: 40px; font-family: courier new,monospace;">
(define-syntax (cond-it stx)<br> (syntax-case stx (else)<br> ((~) #'(void))<br> ((~ (else exp exp2 ...))<br> #'(begin exp exp2 ...))<br> ((~ (test? exp exp2 ...) cond1 ...)<br> (with-syntax ((if-it (datum->syntax #'~ 'if-it)))<br>
#'(if-it test? (begin exp exp2 ...)<br> (cond-it cond1 ...))))))<br><br>> (cond-it (#f 'hello) ("test me" it) (else 'nothing))<br>compile: identifier used out of context in: if-it<br>
</div><br>I guess the app position cannot not be "captured" this way? <br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The macro stepper will show you this using colors. Try an example. The original code is in black. The parts introduced by 'cond-it' are in a different color (like red or blue).<div class="Ih2E3d"></div></blockquote>
<div><br>I'm working in emacs so I don't have macro stepper handy at the moment - is there a way to call macro stepper (a cmdline or repl version) from mzscheme?<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The problem comes from having macros introduce unhygienic bindings of 'it'. A better way to do it would be to bind 'it' to a syntax parameter and update the meaning of 'it' in the expansion of an 'if-it' expression (using 'syntax-parameterize'). </blockquote>
<div><br>This is macro voodoo! ;) I'll have to learn more about syntax parameters and transformers. Is there some sort of guide docs that talks about how and why (usages) on these capabilites?<br><br>Thansks for demonstrating the cool technique and the clear explanation.<br>
yc<br><br></div></div>