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 <ry...@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
____________________ Racket Users list: http://lists.racket-lang.org/users