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

From: Roman Klochkov (kalimehtar at mail.ru)
Date: Thu Apr 3 09:38:00 EDT 2014

 Thank you. This works.
But why (load a) and (module+ test (load a)) have different phases for `a'?


Thu, 3 Apr 2014 11:51:15 +0200 от Jens Axel Søgaard <jensaxel at soegaard.net>:
>It seems the table needs to be created with #:phase -1.
>
>Since syntax-case uses a fender expression I added
>a begin in save-and-define, but it works either way
>(because free-id-table-set! returns a non-false value).
>
>#lang racket
>(require (for-syntax syntax/id-table))
>
>(define-for-syntax table (make-free-id-table #:phase -1))
>
>(define-syntax (save-and-define stx)
>  (syntax-case stx ()
>     [(_ ID)
>      (begin
>        (free-id-table-set! table #'ID 1)
>        #'(define ID 1))]))
>
>(define-syntax (load stx)
>  (syntax-case stx ()
>     [(_ ID2)
>      (if (free-id-table-ref table #'ID2 #f)
>            #''ok
>            #''different)]))
>
>(module+ test
>  (save-and-define a)
>  (displayln (load a)))
>
>-- 
>Jens Axel Søgaard
>
>
>2014-04-03 7:26 GMT+02:00 Roman Klochkov < kalimehtar at mail.ru >:
>> #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)]))
>>
>> (define-syntax (load stx)
>>   (syntax-case stx ()
>>      [(_ ID2)
>>        (if (free-id-table-ref table #'ID2 #f) #''ok #''different)]))
>>
>> (module+ test
>>   (save-and-define a)
>>   (displayln (load a)))
>>
>> ---------
>>
>> Gives 'different. Expected 'ok
>>
>> P.S. If I change last sexp to
>>
>> ;(module+ test
>> (save-and-define a)
>> (displayln (load a))
>>
>> then gives 'ok as expected.
>>
>> Please, help.
>>
>> --
>> Roman Klochkov
>>
>> ____________________
>>   Racket Users list:
>>  http://lists.racket-lang.org/users
>>
>
>
>
>-- 
>--
>Jens Axel Søgaard


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

Posted on the users mailing list.