<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">&nbsp;&nbsp; (define-syntax (sql stx)</font></div><div><font class="Apple-style-span" face="Monaco">&nbsp;&nbsp; &nbsp; &nbsp;(syntax-case stx ()</font></div><div><font class="Apple-style-span" face="Monaco">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;[(_ id)</font></div><div><font class="Apple-style-span" face="Monaco">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; (identifier? #'id)</font></div><div><font class="Apple-style-span" face="Monaco">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; (let ([decl (syntax-local-value #'id)])</font></div><div><font class="Apple-style-span" face="Monaco">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (if (syntax-property decl sql-alias-key)</font></div><div><font class="Apple-style-span" face="Monaco">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #'id</font></div><div><font class="Apple-style-span" face="Monaco">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (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">&nbsp;&nbsp; &nbsp;(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">&nbsp;&nbsp; &nbsp;(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">&nbsp;&nbsp; &nbsp;syntax-local-value: not defined as syntax:&nbsp;</font></div><div><font class="Apple-style-span" face="Monaco">&nbsp;&nbsp; &nbsp;#&lt;syntax:/Users/dave/scheme/alias-test.ss:36:5&gt;</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 &lt;<a href="mailto:d.j.gurnell@gmail.com">d.j.gurnell@gmail.com</a>&gt; 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"> &nbsp;&nbsp;&nbsp;; Define "a" as an alias for the "People" table:<br></blockquote><blockquote type="cite"> &nbsp;&nbsp;&nbsp;(define-alias a People)<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> &nbsp;&nbsp;&nbsp;; Use "a" in a query:<br></blockquote><blockquote type="cite"> &nbsp;&nbsp;&nbsp;(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"> &nbsp;&nbsp;&nbsp;(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"> &nbsp;&nbsp;&nbsp;(define-syntax (define-alias stx)<br></blockquote><blockquote type="cite"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax-case stx ()<br></blockquote><blockquote type="cite"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[(_ id val)<br></blockquote><blockquote type="cite"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(identifier? #'id)<br></blockquote><blockquote type="cite"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(with-syntax ([id (syntax-property #'id sql-alias-key #t)])<br></blockquote><blockquote type="cite"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#'(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"> &nbsp;For list-related administrative tasks:<br></blockquote><blockquote type="cite"> &nbsp;<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>