[racket] Unexpected symbol in namespace-mapped-symbols
Thanks. Much clear now. I didn’t know about the unreadable symbols.
A small example:
(namespace-variable-value (string->unreadable-symbol "!!hi.1") #t
(lambda () "ERROR") !!ns)
Yes, I know that this is a bad idea.
Gustavo
On Fri, Dec 20, 2013 at 7:32 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> The `!!hi.1` symbol is an "unreadable" symbol generated by macro
> expansion (to avoid capturing any other identifier in a source
> program). You can detect such weird symbols with `symbol-unreadable?`.
>
> At Fri, 20 Dec 2013 20:14:30 -0200, Gustavo Massaccesi wrote:
>> I'm not sure that this is a bug. I found this while using
>> define-namespace-anchor.
>>
>> When I run this program I get an unexpected !!hi.1 symbol in the list
>> of namespace-mapped-symbols. (All the variable names begin with !! so
>> they are easy to sort in the list.)
>>
>> The variable !!hi is defined inside a macro, so I expect that it
>> should not be visible from the module namespace. And I can't use
>> namespace-variable-value to get the value of !!hi.1 . Also, if I
>> define a "real" !!hi.1 outside the macro, then there are two !!hi.1
>> symbols in the list.
>>
>> Gustavo
>>
>> ;-----
>> #lang racket
>>
>> (define-syntax-rule (define-hi)
>> (define !!hi #f))
>>
>> (define-hi)
>>
>> (define !!tmp #f)
>> (define !!ns (variable-reference->namespace (#%variable-reference !!tmp)))
>>
>> (define (symbol<? x y)
>> (string<? (symbol->string x) (symbol->string y)))
>>
>> (take (sort (namespace-mapped-symbols !!ns) symbol<?) 5)
>> ;==> '(!!hi.1 !!ns !!tmp #%app #%datum)
>>
>> ;;;(define !!hi.1 #t)
>> ;-----
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users