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