Hello all,<div><br></div><div>I am reading through the PLT Scheme Guide section on Generating Macros (<a href="http://docs.plt-scheme.org/guide/pattern-macros.html#(part._.Macro-.Generating_.Macros)">http://docs.plt-scheme.org/guide/pattern-macros.html#(part._.Macro-.Generating_.Macros)</a> A number of the examples in this section depend on the macro define-get/put-id, which is defined (seemingly just as the appropriate macroexpansion for one case rather than for the general case) as :<div>
<span class="Apple-style-span" style="font-family: fantasy; font-size: medium; "><p><table cellspacing="0" class="schemeblock"><tbody><tr><td style="padding-left: 0px; padding-right: 0px; vertical-align: baseline; "><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); "><a href="http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/misc..ss)._define-syntax-rule))" class="schemesyntaxlink" style="text-decoration: none; color: black; font-weight: bold; ">define-syntax-rule</a></span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">define-get/put-id</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">id</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">get</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">put!</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span></td>
</tr><tr><td style="padding-left: 0px; padding-right: 0px; vertical-align: baseline; "><span class="schemeplain"><span class="hspace" style="font-family: monospace; "> </span></span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); "><a href="http://docs.plt-scheme.org/reference/define.html#(form._((lib._scheme/private/define..ss)._define-syntax))" class="schemesyntaxlink" style="text-decoration: none; color: black; font-weight: bold; ">define-syntax</a></span><span class="hspace" style="font-family: monospace; "> </span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">clock</span></td>
</tr><tr><td style="padding-left: 0px; padding-right: 0px; vertical-align: baseline; "><span class="schemeplain"><span class="hspace" style="font-family: monospace; "> </span></span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); "><a href="http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/stxcase-scheme..ss)._syntax-id-rules))" class="schemesyntaxlink" style="text-decoration: none; color: black; font-weight: bold; ">syntax-id-rules</a></span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); "><a href="http://docs.plt-scheme.org/reference/set_.html#(form._((quote._~23~25kernel)._set!))" class="schemesyntaxlink" style="text-decoration: none; color: black; font-weight: bold; ">set!</a></span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span></td>
</tr><tr><td style="padding-left: 0px; padding-right: 0px; vertical-align: baseline; "><span class="schemeplain"><span class="hspace" style="font-family: monospace; "> </span></span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">[</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); "><a href="http://docs.plt-scheme.org/reference/set_.html#(form._((quote._~23~25kernel)._set!))" class="schemesyntaxlink" style="text-decoration: none; color: black; font-weight: bold; ">set!</a></span><span class="hspace" style="font-family: monospace; "> </span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">clock</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">e</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">put-clock!</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">e</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">]</span></td>
</tr><tr><td style="padding-left: 0px; padding-right: 0px; vertical-align: baseline; "><span class="schemeplain"><span class="hspace" style="font-family: monospace; "> </span></span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">[</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">clock</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">a</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); "><a href="http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/stxcase-scheme..ss)._......))" class="schemesyntaxlink" style="text-decoration: none; color: black; font-weight: bold; ">...</a></span><span class="hspace" style="font-family: monospace; "> </span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); "><a href="http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/stxcase-scheme..ss)._......))" class="schemesyntaxlink" style="text-decoration: none; color: black; font-weight: bold; ">...</a></span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">get-clock</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">a</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); "><a href="http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/stxcase-scheme..ss)._......))" class="schemesyntaxlink" style="text-decoration: none; color: black; font-weight: bold; ">...</a></span><span class="hspace" style="font-family: monospace; "> </span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); "><a href="http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/stxcase-scheme..ss)._......))" class="schemesyntaxlink" style="text-decoration: none; color: black; font-weight: bold; ">...</a></span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">]</span></td>
</tr><tr><td style="padding-left: 0px; padding-right: 0px; vertical-align: baseline; "><span class="schemeplain"><span class="hspace" style="font-family: monospace; "> </span></span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">[</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">clock</span><span class="hspace" style="font-family: monospace; "> </span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">(</span><span class="schemesymbol" style="font-family: monospace; color: rgb(38, 38, 128); ">get-clock</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">]</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)</span><span class="schemeparen" style="font-family: monospace; color: rgb(132, 60, 36); ">)<br>
</span></td></tr></tbody></table></p></span></div><div>I simply adapted it to the general case and got:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">
(define-syntax-rule (define-get/put-id id get put!)<br> (define-syntax id<br> (syntax-id-rules (set!)<br> [(set! id e) (put! e)]<br> [(id a (... ...)) ((get) a (... ...))]<br> [id (get)])))</blockquote>
<div><div><br></div><div>Which works, surprisingly, and confuses me. Generally define-syntax does not evaluate the first argument but uses it as a symbol naming the item in the syntax, but in this case, id is a identifier which gets evaluated so that the passed value of id is used as the actual syntax. Does define-syntax check in the environment and use the literal symbol as its name unless it has a defined value as an identifier? I tried to look this up in the documentation for define-syntax but quickly got confused.</div>
<div><br></div><div>Thanks,</div><div><br></div><div>Adam</div></div></div>