Re: [racket-users] syntax-original? different in expanded code than during expansion

2017-09-20 Thread Robby Findler
In my opinion, it is too hard, not too easy to synthesize such syntax
objects. After all, I can make ports and I can call read-syntax (which
is what I end up doing sometimes, annoyingly). The point is that
syntax-original? implies that DrRacket treats the syntax objects
differently. Most of the time, it is just right, but for some
languages (those that don't use Racket's reader), there is an annoying
dance one has to do in order to make an identifier that will cooperate
properly.

Robby


On Wed, Sep 20, 2017 at 5:21 PM, Matthias Felleisen
 wrote:
>
> Is it a good idea that we can synthesize “original looking code”?
>
>
>> On Sep 20, 2017, at 4:48 PM, Alexis King  wrote:
>>
>> To understand this, note that (syntax-original? stx) is only #t when
>> *both* of the following things are true:
>>
>>  1. stx has the special, opaque syntax property that syntax-original?
>> knows how to look for.
>>
>>  2. stx has no macro-introduction scopes.
>>
>> The first point is satisfied by read-syntax, which attaches the syntax
>> property to syntax it reads. The second is a secondary check, which
>> ensures macro-introduced syntax will not be treated as original, even
>> though the syntax objects produced by quote-syntax *will* have the
>> “originalness” property.
>>
>> Remember, however, that the way the Racket macro system tracks which
>> syntax objects are macro-introduced is by applying the
>> macro-introduction scope to the syntax object that is the input to a
>> syntax transformer, then flipping the scope on the result. This means
>> that one must apply syntax-local-introduce to any syntax objects that
>> come from a macro transformer’s input to remove the macro-introduction
>> scope. In your example, stx contains the macro-introduction scope for
>> the use of exp, so syntax-original? does not treat the syntax as
>> original. This slightly modified program exhibits the behavior you
>> expect by adding a use of syntax-local-introduce:
>>
>>  #lang racket
>>
>>  (define-syntax (exp stx)
>>(define a (local-expand (cadr (syntax->list stx)) 'expression '()))
>>(define one (syntax-local-introduce (cadr (syntax->list a
>>(displayln (list one (syntax-original? one)))
>>a)
>>
>>  (exp 1)
>>
>> Since the macro-introduction scope is flipped by the expander on the
>> result of each macro, the syntax object returned by your macro has its
>> syntax macro-introduction scope removed, and the macro stepper sees that
>> expanded piece of syntax. Therefore, it reports that it is original even
>> though your macro does not.
>>
>> Alexis
>>
>>> On Sep 20, 2017, at 11:48 AM, Spencer Florence
>>>  wrote:
>>>
>>> The program:
>>>
>>> ```
>>> #lang racket
>>>
>>> (define-syntax (exp stx)
>>>  (define a (local-expand (cadr (syntax->list stx)) 'expression '()))
>>>  (define one (cadr (syntax->list a)))
>>>  (displayln (list one (syntax-original? one)))
>>>  a)
>>>
>>> (exp 1)
>>> ```
>>>
>>> prints `(# #f)`.
>>>
>>> However if I open the macro stepper in and step to the end, the macro
>>> stepper shows the corresponding `1` as `original?: #t`.
>>>
>>> Why are these different?
>>>
>>> --spencer
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] syntax-original? different in expanded code than during expansion

2017-09-20 Thread Matthias Felleisen

Is it a good idea that we can synthesize “original looking code”? 


> On Sep 20, 2017, at 4:48 PM, Alexis King  wrote:
> 
> To understand this, note that (syntax-original? stx) is only #t when
> *both* of the following things are true:
> 
>  1. stx has the special, opaque syntax property that syntax-original?
> knows how to look for.
> 
>  2. stx has no macro-introduction scopes.
> 
> The first point is satisfied by read-syntax, which attaches the syntax
> property to syntax it reads. The second is a secondary check, which
> ensures macro-introduced syntax will not be treated as original, even
> though the syntax objects produced by quote-syntax *will* have the
> “originalness” property.
> 
> Remember, however, that the way the Racket macro system tracks which
> syntax objects are macro-introduced is by applying the
> macro-introduction scope to the syntax object that is the input to a
> syntax transformer, then flipping the scope on the result. This means
> that one must apply syntax-local-introduce to any syntax objects that
> come from a macro transformer’s input to remove the macro-introduction
> scope. In your example, stx contains the macro-introduction scope for
> the use of exp, so syntax-original? does not treat the syntax as
> original. This slightly modified program exhibits the behavior you
> expect by adding a use of syntax-local-introduce:
> 
>  #lang racket
> 
>  (define-syntax (exp stx)
>(define a (local-expand (cadr (syntax->list stx)) 'expression '()))
>(define one (syntax-local-introduce (cadr (syntax->list a
>(displayln (list one (syntax-original? one)))
>a)
> 
>  (exp 1)
> 
> Since the macro-introduction scope is flipped by the expander on the
> result of each macro, the syntax object returned by your macro has its
> syntax macro-introduction scope removed, and the macro stepper sees that
> expanded piece of syntax. Therefore, it reports that it is original even
> though your macro does not.
> 
> Alexis
> 
>> On Sep 20, 2017, at 11:48 AM, Spencer Florence
>>  wrote:
>> 
>> The program:
>> 
>> ```
>> #lang racket
>> 
>> (define-syntax (exp stx)
>>  (define a (local-expand (cadr (syntax->list stx)) 'expression '()))
>>  (define one (cadr (syntax->list a)))
>>  (displayln (list one (syntax-original? one)))
>>  a)
>> 
>> (exp 1)
>> ```
>> 
>> prints `(# #f)`.
>> 
>> However if I open the macro stepper in and step to the end, the macro
>> stepper shows the corresponding `1` as `original?: #t`.
>> 
>> Why are these different?
>> 
>> --spencer
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.