[plt-scheme] Recognising identifiers bound with a certain macro

From: Dave Gurnell (d.j.gurnell at gmail.com)
Date: Fri Feb 8 11:19:15 EST 2008

Hmmm... I must be doing it wrong. Here's a stripped down version of my  
"sql" macro:

    (define-syntax (sql stx)
       (syntax-case stx ()
         [(_ id)
          (identifier? #'id)
          (let ([decl (syntax-local-value #'id)])
            (if (syntax-property decl sql-alias-key)
              #'id
              (raise-syntax-error #f "Not an SQL alias." stx #'id)))]))

If I try this with the test-code:

     (define-alias a 1)

     (sql a)

I get:

     syntax-local-value: not defined as syntax:
     #<syntax:/Users/dave/scheme/alias-test.ss:36:5>

where 36:5 is the position of the "a" in "(sql a)".

-- Dave

> syntax-local-value?
>
> Robby
>
> On Feb 8, 2008 7:51 AM, Dave Gurnell <d.j.gurnell at gmail.com> wrote:
>> Hi all,
>>
>> I have a macro, "define-alias", that I'm using to define table  
>> aliases in a
>> Scheme wrapper for SQL:
>>
>>    ; Define "a" as an alias for the "People" table:
>>    (define-alias a People)
>>
>>    ; Use "a" in a query:
>>    (sql (select #:from a ...))
>>
>> In my "sql" macro, I'd like to be able to distinguish between  
>> identifiers
>> bound with "define-alias" and other identifiers bound with other  
>> forms. My
>> current approach is to use a syntax property to uniquely mark  
>> aliases:
>>
>>    (define-for-syntax sql-alias-key (gensym 'sql-alias-key))
>>
>>
>>    (define-syntax (define-alias stx)
>>      (syntax-case stx ()
>>        [(_ id val)
>>         (identifier? #'id)
>>         (with-syntax ([id (syntax-property #'id sql-alias-key #t)])
>>           #'(define id val)))]))
>>
>> This all seems to do what I want, but I can't work out how to get  
>> from the
>> identifier in the "sql" macro back to the binding identifier in the
>> "define-alias".
>>
>> Can anyone provide the missing link (or perhaps syntax properties  
>> aren't the
>> right tool for the job)?
>>
>> Many thanks,
>>
>> -- Dave
>> _________________________________________________
>>  For list-related administrative tasks:
>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080208/2a58f9f5/attachment.html>

Posted on the users mailing list.