<HTML><BODY>Thank you. This works.<br>But why (load a) and (module+ test (load a)) have different phases for `a'?<br><br><br>Thu, 3 Apr 2014 11:51:15 +0200 от Jens Axel Søgaard <jensaxel@soegaard.net>:<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_13965186770000000798_BODY">It seems the table needs to be created with #:phase -1.<br>
<br>
Since syntax-case uses a fender expression I added<br>
a begin in save-and-define, but it works either way<br>
(because free-id-table-set! returns a non-false value).<br>
<br>
#lang racket<br>
(require (for-syntax syntax/id-table))<br>
<br>
(define-for-syntax table (make-free-id-table #:phase -1))<br>
<br>
(define-syntax (save-and-define stx)<br>
(syntax-case stx ()<br>
[(_ ID)<br>
(begin<br>
(free-id-table-set! table #'ID 1)<br>
#'(define ID 1))]))<br>
<br>
(define-syntax (load stx)<br>
(syntax-case stx ()<br>
[(_ ID2)<br>
(if (free-id-table-ref table #'ID2 #f)<br>
#''ok<br>
#''different)]))<br>
<br>
(module+ test<br>
(save-and-define a)<br>
(displayln (load a)))<br>
<br>
-- <br>
Jens Axel Søgaard<br>
<br>
<br>
2014-04-03 7:26 GMT+02:00 Roman Klochkov <<a href="/compose?To=kalimehtar@mail.ru">kalimehtar@mail.ru</a>>:<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>
> (define-syntax (load stx)<br>
> (syntax-case stx ()<br>
> [(_ ID2)<br>
> (if (free-id-table-ref table #'ID2 #f) #''ok #''different)]))<br>
><br>
> (module+ test<br>
> (save-and-define a)<br>
> (displayln (load a)))<br>
><br>
> ---------<br>
><br>
> Gives 'different. Expected 'ok<br>
><br>
> P.S. If I change last sexp to<br>
><br>
> ;(module+ test<br>
> (save-and-define a)<br>
> (displayln (load a))<br>
><br>
> then gives 'ok as expected.<br>
><br>
> Please, help.<br>
><br>
> --<br>
> Roman Klochkov<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>
><br>
<br>
<br>
<br>
-- <br>
--<br>
Jens Axel Søgaard<br>
</div>
<base href="https://e.mail.ru/" target="_self">
</div>
</div>
</div>
</blockquote>
<br>
<br>-- <br>Roman Klochkov<br></BODY></HTML>