[racket] free-id-table. Is it a bug?

From: Roman Klochkov (kalimehtar at mail.ru)
Date: Thu Apr 3 12:42:42 EDT 2014

 Thank you! Now I understand how to do it right.

> but then the 
   code it produces (the definition) changes the binding of ID

Then why code without (module+ ..) works fine? Even in REPL all is fine.


Thu, 03 Apr 2014 09:37:33 -0400 от Ryan Culpepper <ryanc at ccs.neu.edu>:
>On 04/03/2014 01:26 AM, Roman Klochkov wrote:
>> #lang racket
>> (require (for-syntax syntax/id-table))
>>
>> (define-for-syntax table (make-free-id-table))
>>
>> (define-syntax (save-and-define stx)
>>    (syntax-case stx ()
>>       [(_ ID) (free-id-table-set! table #'ID 1) #'(define ID 1)]))
>
>The problem is that save-and-define puts ID in the table, but then the 
>code it produces (the definition) changes the binding of ID, so when you 
>try to look it up the two versions of ID might not match.
>
>The fix is to put the table update after the definition:
>
>(define-syntax (save-and-define stx)
>   (syntax-case stx ()
>     [(_ ID)
>      #'(begin
>          (define ID 1)
>          (begin-for-syntax
>            (free-id-table-set! table #'ID 1)))]))
>
>Or if you want this to work in internal definition contexts:
>
>(define-syntax (save-and-define stx)
>   (syntax-case stx ()
>     [(_ ID)
>      #'(begin
>          (define ID 1)
>          (define-syntaxes ()
>            (begin0 (values) (free-id-table-set! table #'ID 1))))]))
>
>Ryan
>
>____________________
>  Racket Users list:
>   http://lists.racket-lang.org/users


-- 
Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140403/9d01b2de/attachment.html>

Posted on the users mailing list.