<HTML><BODY>Thank you! Now I understand how to do it right.<br><br>> but then the <br> code it produces (the definition) changes the binding of ID<br><br>Then why code without (module+ ..) works fine? Even in REPL all is fine.<br><br><br>Thu, 03 Apr 2014 09:37:33 -0400 от Ryan Culpepper <ryanc@ccs.neu.edu>:<br>
<blockquote style="margin: 10px; padding: 0px 0px 0px 10px; border-left-color: rgb(8, 87, 166); border-left-width: 1px; border-left-style: solid;">
<div>
<div class="js-helper js-readmsg-msg">
<style type="text/css"></style>
<div>
<base href="https://e.mail.ru/" target="_self">
<div id="style_13965328080000000158_BODY">On 04/03/2014 01:26 AM, Roman Klochkov wrote:<br>
> #lang racket<br>
> (require (for-syntax syntax/id-table))<br>
><br>
> (define-for-syntax table (make-free-id-table))<br>
><br>
> (define-syntax (save-and-define stx)<br>
> (syntax-case stx ()<br>
> [(_ ID) (free-id-table-set! table #'ID 1) #'(define ID 1)]))<br>
<br>
The problem is that save-and-define puts ID in the table, but then the <br>
code it produces (the definition) changes the binding of ID, so when you <br>
try to look it up the two versions of ID might not match.<br>
<br>
The fix is to put the table update after the definition:<br>
<br>
(define-syntax (save-and-define stx)<br>
(syntax-case stx ()<br>
[(_ ID)<br>
#'(begin<br>
(define ID 1)<br>
(begin-for-syntax<br>
(free-id-table-set! table #'ID 1)))]))<br>
<br>
Or if you want this to work in internal definition contexts:<br>
<br>
(define-syntax (save-and-define stx)<br>
(syntax-case stx ()<br>
[(_ ID)<br>
#'(begin<br>
(define ID 1)<br>
(define-syntaxes ()<br>
(begin0 (values) (free-id-table-set! table #'ID 1))))]))<br>
<br>
Ryan<br>
<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div>
<base href="https://e.mail.ru/" target="_self">
</div>
</div>
</div>
</blockquote>
<br>
<br>-- <br>Roman Klochkov<br></BODY></HTML>