Hi all - <div><br></div><div>I am running into a difference of behaviors when I define a procedure with syntax-case via `begin-for-syntax` versus requiring it from another module via (require (for-syntax ...)). It seems that if the procedure has syntax-case literals defined, the literal-matching works if the procedure is defined via `begin-for-syntax`, but not when imported via `require`/`for-syntax`. </div>
<div><br></div><div>Any idea on what I am missing/misusing here? </div><div><br></div><div>Below is an example with literal.ss and test-literal.ss showing that it does not work: </div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div><font face="'courier new', monospace">;; literal.ss - cond* matches a cond-like syntax and convert it to an nested if syntax. has an `else` syntax-case literal </font></div>
<div><div><font face="'courier new', monospace">#lang scheme/base</font></div></div><div><div><font face="'courier new', monospace">(define (cond* stx)</font></div>
</div><div><div><font face="'courier new', monospace"> (syntax-case stx (<b>else</b>) </font></div></div><div><div><font face="'courier new', monospace"> ((~)</font></div>
</div><div><div><font face="'courier new', monospace"> #`(void))</font></div></div><div><div><font face="'courier new', monospace"> ((~ (<b>else</b> exp exp2 ...))</font></div>
</div><div><div><font face="'courier new', monospace"> #`(begin (void) exp exp2 ...))</font></div></div><div><div><font face="'courier new', monospace"> ((~ (test exp exp2 ...) rest ...) </font></div>
</div><div><div><font face="'courier new', monospace"> #`(if test</font></div></div><div><div><font face="'courier new', monospace"> (begin exp exp2 ...) </font></div>
</div><div><div><font face="'courier new', monospace"> #,(cond* #`(cond* #,@#'(rest ...)))))</font></div></div><div><div><font face="'courier new', monospace"> )) </font></div>
</div><div><div><font face="'courier new', monospace"><br></font></div></div><div><div><font face="'courier new', monospace">(provide cond*)</font></div></div>
</blockquote><div><div><br></div></div><div>And test-literal.ss requires literal.ss via for-syntax, where `cond/` uses `cond*`, and it resulted in an error, because the else arm is transformed via the `if` arm instead of the `else` arm (when stepped via Macro Stepper): </div>
<div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font face="'courier new', monospace">;; test-literal.ss </font></div>
</div><div><div><font face="'courier new', monospace">#lang scheme/base</font></div></div><div><div><font face="'courier new', monospace">(require (for-syntax scheme/base</font></div>
</div><div><div><font face="'courier new', monospace"> "literal.ss"</font></div></div><div><div><font face="'courier new', monospace"> )</font></div>
</div><div><div><font face="'courier new', monospace"> )</font></div></div><div><div><font face="'courier new', monospace"><br></font></div></div><div>
<div><font face="'courier new', monospace">(define-syntax (cond/ stx)</font></div></div><div><div><font face="'courier new', monospace"> (syntax-case stx () </font></div>
</div><div><div><font face="'courier new', monospace"> (stx</font></div></div><div><div><font face="'courier new', monospace"> (cond* #'stx))</font></div>
</div><div><div><font face="'courier new', monospace"> ))</font></div></div><div><div><font face="'courier new', monospace"><br></font></div></div><div>
<div><font face="'courier new', monospace">(cond/ (#f 2) (<b>else</b> 5)) ;; error: compile: unbound identifier (and no #%app syntax transformer is bound) in: if...</font></div></div></blockquote>
<div><br></div><div>But if `cond*` is defined via `begin-for-syntax` as shown in test-literal2.ss, then it works accordingly: </div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div><div><font face="'courier new', monospace">;; test-literal2.ss </font></div><div><font face="'courier new', monospace">#lang scheme/base</font></div></div>
<div><div><font face="'courier new', monospace">(require (for-syntax scheme/base</font></div></div><div><div><font face="'courier new', monospace"> )</font></div>
</div><div><div><font face="'courier new', monospace"> )</font></div></div><div><div><font face="'courier new', monospace">(begin-for-syntax </font></div>
</div><div><div><font face="'courier new', monospace"> (define (cond* stx)</font></div></div><div><div><font face="'courier new', monospace"> (syntax-case stx (<b>else</b>) </font></div>
</div><div><div><font face="'courier new', monospace"> ((~)</font></div></div><div><div><font face="'courier new', monospace"> #`(void))</font></div>
</div><div><div><font face="'courier new', monospace"> ((~ (<b>else</b> exp exp2 ...))</font></div></div><div><div><font face="'courier new', monospace"> #`(begin (void) exp exp2 ...))</font></div>
</div><div><div><font face="'courier new', monospace"> ((~ (test exp exp2 ...) rest ...) </font></div></div><div><div><font face="'courier new', monospace"> #`(if test</font></div>
</div><div><div><font face="'courier new', monospace"> (begin exp exp2 ...) </font></div></div><div><div><font face="'courier new', monospace"> #,(cond* #`(cond* #,@#'(rest ...)))))</font></div>
</div><div><div><font face="'courier new', monospace"> )) </font></div></div><div><div><font face="'courier new', monospace"> )</font></div></div><div>
<div><font face="'courier new', monospace"><br></font></div></div><div><div><font face="'courier new', monospace">(define-syntax (cond/ stx)</font></div></div>
<div><div><font face="'courier new', monospace"> (syntax-case stx () </font></div></div><div><div><font face="'courier new', monospace"> (stx</font></div>
</div><div><div><font face="'courier new', monospace"> (cond* #'stx))</font></div></div><div><div><font face="'courier new', monospace"> ))</font></div>
</div><div><div><font face="'courier new', monospace"><br></font></div></div><div><div><font face="'courier new', monospace">(cond/ (#f 2) (<b>else</b> 5)) ;; works => 5 </font></div>
</div></blockquote><div><div><br></div><div>Any ideas on the differences are appreciated. Thanks. </div><div>yc</div><div><br></div><div><br></div><div> </div></div><div><br></div><div><br></div><div>
<br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br>
<div><br></div><div><br></div>
</div>