Hi all - <br><br>I am running into issues composing a couple of syntax-case macros, and not sure where things go wrong. When I try to write a `cond-it` using an working `if-it` and `when-it`, I was unable to capture `it` within `cond-it`. <br>
<br style="font-family: courier new,monospace;"><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">;; the working if-it & when-it</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">(define-syntax (if-it stx)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (syntax-case stx ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ((if-it test? then else)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (with-syntax ((it (datum->syntax #'if-it 'it)))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> #'(let ((it test?))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (if it then else)))))) </span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(define-syntax (when-it stx)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (syntax-case stx ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ((~ test? exp exp2 ...)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (with-syntax ((it (datum->syntax #'~ 'it)))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> #'(let ((it test?)) (when it exp exp2 ...))))))</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">;; the non-working cond-it </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">(define-syntax (cond-it stx)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (syntax-case stx (else)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ((cond-it (else exp exp2 ...))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #'(begin exp exp2 ...))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ((cond-it (test? exp exp2 ...))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #'(when-it test? exp exp2 ...))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ((cond-it (test? exp exp2 ...) cond1 cond2 ...)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #'(if-it test? (begin exp exp2 ...)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (cond-it cond1 cond2 ...)))))</span><br></div><br>I tried to capture the `it` binding as well - but it still doesn't work.<br><br><div style="margin-left: 40px; font-family: courier new,monospace;">
(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> (with-syntax ((it (datum->syntax #'cond-it 'it)))<br>
#'(when-it test? exp exp2 ...)))<br> ((cond-it (test? exp exp2 ...) cond1 cond2 ...)<br> (with-syntax ((it (datum->syntax #'cond-it 'it)))<br> #'(if-it test? (begin exp exp2 ...)<br>
(cond-it cond1 cond2 ...))))))<br></div><br>When I finally write `cond-it` without using `if-it` and `when-it`, it worked.<br><br><div style="margin-left: 40px; font-family: courier new,monospace;">(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> (with-syntax ((it (datum->syntax #'cond-it 'it)))<br> #'(let ((it test?)) (when it exp exp2 ...))))<br>
((cond-it (test? exp exp2 ...) cond cond2 ...)<br> (with-syntax ((it (datum->syntax #'cond-it 'it)))<br> #'(let ((it test?))<br> (if it (begin exp exp2 ...)<br> (cond-it cond cond2 ...)))))))<br>
</div><br>What am I missing here? How can `cond-it` be composed of `if-it` and `when-it`?<br><br>Any tips are appreciated. Thanks,<br>yc<br><br><br>