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`.&nbsp; <br>
<br style="font-family: courier new,monospace;"><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">;; the working if-it &amp; 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;">&nbsp; (syntax-case stx ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; ((if-it test? then else)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp; (with-syntax ((it (datum-&gt;syntax #&#39;if-it &#39;it)))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(let ((it test?))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (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;">&nbsp; (syntax-case stx ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; ((~ test? exp exp2 ...)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp; (with-syntax ((it (datum-&gt;syntax #&#39;~ &#39;it)))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(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;">&nbsp; (syntax-case stx (else)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; ((cond-it (else exp exp2 ...))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(begin exp exp2 ...))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; ((cond-it (test? exp exp2 ...))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(when-it test? exp exp2 ...))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; ((cond-it (test? exp exp2 ...) cond1 cond2 ...)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(if-it test? (begin exp exp2 ...)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cond-it cond1 cond2 ...)))))</span><br></div><br>I tried to capture the `it` binding as well - but it still doesn&#39;t work.<br><br><div style="margin-left: 40px; font-family: courier new,monospace;">
(define-syntax (cond-it stx)<br>&nbsp; (syntax-case stx (else)<br>&nbsp;&nbsp;&nbsp; ((cond-it (else exp exp2 ...))<br>&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(begin exp exp2 ...))<br>&nbsp;&nbsp;&nbsp; ((cond-it (test? exp exp2 ...))<br>&nbsp;&nbsp;&nbsp;&nbsp; (with-syntax ((it (datum-&gt;syntax #&#39;cond-it &#39;it)))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(when-it test? exp exp2 ...)))<br>&nbsp;&nbsp;&nbsp; ((cond-it (test? exp exp2 ...) cond1 cond2 ...)<br>&nbsp;&nbsp;&nbsp;&nbsp; (with-syntax ((it (datum-&gt;syntax #&#39;cond-it &#39;it)))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(if-it test? (begin exp exp2 ...)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (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>
&nbsp; (syntax-case stx (else)<br>&nbsp;&nbsp;&nbsp; ((cond-it (else exp exp2 ...))<br>&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(begin exp exp2 ...))<br>&nbsp;&nbsp;&nbsp; ((cond-it (test? exp exp2 ...))<br>&nbsp;&nbsp;&nbsp;&nbsp; (with-syntax ((it (datum-&gt;syntax #&#39;cond-it &#39;it)))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(let ((it test?)) (when it exp exp2 ...))))<br>
&nbsp;&nbsp;&nbsp; ((cond-it (test? exp exp2 ...) cond cond2 ...)<br>&nbsp;&nbsp;&nbsp;&nbsp; (with-syntax ((it (datum-&gt;syntax #&#39;cond-it &#39;it)))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&#39;(let ((it test?))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (if it (begin exp exp2 ...)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cond-it cond cond2 ...)))))))<br>
</div><br>What am I missing here?&nbsp; How can `cond-it` be composed of `if-it` and `when-it`?<br><br>Any tips are appreciated.&nbsp; Thanks,<br>yc<br><br><br>