[racket] How to make an identifier that will have a certain binding no matter what phase level it's referenced at?
On Jul 27, 2014, at 1:37 PM, Roman Klochkov <kalimehtar at mail.ru> wrote:
> I looked into https://github.com/qerub/rackjure/blob/master/rackjure/lambda-reader.rkt
> As far as I understand, reader-proce returns #'(lambda ...) for #λ(...).
> But, according to http://docs.racket-lang.org/reference/reader-procs.html it should return (datum->syntax #f '(lambda ...))
> Maybe, this is the source of the error
No, it’s actually a good thing that it returns #’(lambda …) because I want the lambda to be bound to the lambda from racket/base no matter what bindings there might be in the file it’s used in. That’s one great thing about hygienic macros and syntax-objects. For example this works fine:
#lang rackjure
(require rackunit)
(define lambda "whatever")
(check-equal? (map #λ(+ % %2) '(1 2 3) '(1 2 3))
'(2 4 6))
If it were (datum->syntax #f ‘(lambda …) it wouldn’t work.
That’s why it’s #’(lambda …) instead of (datum->syntax #f '(lambda …)).
>
> Sun, 27 Jul 2014 12:21:36 -0400 от "Alexander D. Knauth" <alexander at knauth.org>:
>> I just tried to try it and see if it worked, when I realized that it won’t work because I can’t use quote-syntax.
>>
>> Is there any way to get around that? And would it even work anyway?
>> On Jul 27, 2014, at 6:59 AM, Roman Klochkov < kalimehtar at mail.ru > wrote:
>>> Maybe via " Cross-Phase Persistent Module Declarations" http://docs.racket-lang.org/reference/syntax-model.html#%28part._cross-phase._persistent-grammar%29 ?
>>>
>>>
>>> Thu, 24 Jul 2014 21:24:20 -0400 от "Alexander D. Knauth" < alexander at knauth.org >:
>>>> How can I make an identifier that will have a certain binding no matter what phase level it's referenced at?
>>>>
>>>> For example if I’m making a reader extension that will produce a lambda expression, how do I make it so that the lambda expression will be able to exist at any phase level?
>>>>
>>>> For example this program using #lang rackjure doesn’t work:
>>>> #lang rackjure
>>>> (require (for-meta 1 racket/base)
>>>> (for-meta 2 racket/base)
>>>> (for-meta 3 racket/base)
>>>> (for-meta 4 racket/base)
>>>> )
>>>>
>>>> #λ(* 2 %) ; works, produces approx. (lambda (%) (* 2 %))
>>>> (begin-for-syntax
>>>> (begin-for-syntax
>>>> #λ(* 2 %) ; lambda: unbound identifier at phase 2;
>>>> ; ; also, no #%app syntax transformer is bound in: lambda
>>>> ))
>>>>
>>>> Is there any way to construct an identifier that would be bound to lambda from racket/base no matter what phase level it’s used in?
>>>>
>>>>
>>>> ____________________
>>>> Racket Users list:
>>>> http://lists.racket-lang.org/users
>>>>
>>>
>>>
>>> --
>>> Roman Klochkov
>
>
> --
> Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140727/72615463/attachment-0001.html>