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)))

  (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.


> 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 `(#<tmp.rkt:10:5 1> #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 
For more options, visit

Reply via email to