<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div><div>A macro like<br><br></div>(define-syntax (mac stx)<br></div>  (... generate user scope function by passing stx to format-id ...))<br><br>
</div>doesn't work (function is unbound in phase 0) if I use optional parameters and telescoping cases:<br><br></div><div>(syntax-case ...<br></div>  [(_ param ...) #'(mac some-default-thing param ...)]<br></div>  [(_ optional-thing param ...) #'the-main-expansion]<br>
<br></div>This is presumably because the second call to "mac" is now in a different context.  The solution I have is to thread stx through recursive calls:<br><br></div>(define-syntax (mac stx)<br></div>  (define (aux original-stx stx)<br>
</div>    ( ... cases here and pass original-stx to format-id ... )<br></div>  (syntax-case stx ()<br></div>    [(orig rest ...) (aux #'orig #'(rest ...))]))<br><br></div>I was hoping there was something that stores the context of the original macro call for just this kind of thing, so it could be written like the first version but with permanent access to its original call's context through nested expansion code, or perhaps I'm going about it wrong.  Also, in the above example, orig != stx in the sense that passing stx to format-id results in the undefined in phase 0 error:<br>
<br>(define-syntax (mac stx)<br>  (define (aux aux-stx)<br></div><div>    (... cases here and pass stx to format-id ...)<br></div><div>  (aux stx))<br><br></div><div>What makes that fail?<br></div></div></div>