<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hmmm... I must be doing it wrong. Here's a stripped down version of my "sql" macro:</div><div><br class="webkit-block-placeholder"></div><div><div><font class="Apple-style-span" face="Monaco"> (define-syntax (sql stx)</font></div><div><font class="Apple-style-span" face="Monaco"> (syntax-case stx ()</font></div><div><font class="Apple-style-span" face="Monaco"> [(_ id)</font></div><div><font class="Apple-style-span" face="Monaco"> (identifier? #'id)</font></div><div><font class="Apple-style-span" face="Monaco"> (let ([decl (syntax-local-value #'id)])</font></div><div><font class="Apple-style-span" face="Monaco"> (if (syntax-property decl sql-alias-key)</font></div><div><font class="Apple-style-span" face="Monaco"> #'id</font></div><div><font class="Apple-style-span" face="Monaco"> (raise-syntax-error #f "Not an SQL alias." stx #'id)))]))</font></div><div><br></div><div>If I try this with the test-code:</div><div><br></div><div><font class="Apple-style-span" face="Monaco"> (define-alias a 1)</font></div><div><font class="Apple-style-span" face="Monaco"><br class="webkit-block-placeholder"></font></div><div><font class="Apple-style-span" face="Monaco"> (sql a)</font></div><div><br class="webkit-block-placeholder"></div><div>I get:</div><div><br class="webkit-block-placeholder"></div><div><div><font class="Apple-style-span" face="Monaco"> syntax-local-value: not defined as syntax: </font></div><div><font class="Apple-style-span" face="Monaco"> #<syntax:/Users/dave/scheme/alias-test.ss:36:5></font></div><div><br></div><div>where 36:5 is the position of the "a" in "(sql a)".</div><div><br class="webkit-block-placeholder"></div></div><div>-- Dave</div></div><div><br class="Apple-interchange-newline"><blockquote type="cite">syntax-local-value?<br><br>Robby<br><br>On Feb 8, 2008 7:51 AM, Dave Gurnell <<a href="mailto:d.j.gurnell@gmail.com">d.j.gurnell@gmail.com</a>> wrote:<br><blockquote type="cite">Hi all,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I have a macro, "define-alias", that I'm using to define table aliases in a<br></blockquote><blockquote type="cite">Scheme wrapper for SQL:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> ; Define "a" as an alias for the "People" table:<br></blockquote><blockquote type="cite"> (define-alias a People)<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> ; Use "a" in a query:<br></blockquote><blockquote type="cite"> (sql (select #:from a ...))<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">In my "sql" macro, I'd like to be able to distinguish between identifiers<br></blockquote><blockquote type="cite">bound with "define-alias" and other identifiers bound with other forms. My<br></blockquote><blockquote type="cite">current approach is to use a syntax property to uniquely mark aliases:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> (define-for-syntax sql-alias-key (gensym 'sql-alias-key))<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> (define-syntax (define-alias stx)<br></blockquote><blockquote type="cite"> (syntax-case stx ()<br></blockquote><blockquote type="cite"> [(_ id val)<br></blockquote><blockquote type="cite"> (identifier? #'id)<br></blockquote><blockquote type="cite"> (with-syntax ([id (syntax-property #'id sql-alias-key #t)])<br></blockquote><blockquote type="cite"> #'(define id val)))]))<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">This all seems to do what I want, but I can't work out how to get from the<br></blockquote><blockquote type="cite">identifier in the "sql" macro back to the binding identifier in the<br></blockquote><blockquote type="cite">"define-alias".<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Can anyone provide the missing link (or perhaps syntax properties aren't the<br></blockquote><blockquote type="cite">right tool for the job)?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Many thanks,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">-- Dave<br></blockquote><blockquote type="cite">_________________________________________________<br></blockquote><blockquote type="cite"> For list-related administrative tasks:<br></blockquote><blockquote type="cite"> <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote></blockquote></div><br></body></html>