[plt-scheme] local special syntax confusion
Psy-Kosh wrote:
> First, thank you for taking the time to reply.
>
> Spent a bit of time reading and thinking about your explanation, and I
> think I have a _partial_ grasp, but only a partial one.
>
>> The application isn't in the scope of the nonhygienically introduced
>> binding, because it's in the right-hand side of 'let-syntax'.
>>
>
> Sorry, that's one (the main) bit I don't follow. ie, in the let-syntax
> expression, shouldn't the #%app that's explicitly there be replaced with
> the syntax object from the with-syntax form? That is, I don't quite
> follow why it's not. (or did you mean it is, but somehow the implicit
> #%app later doesn't see it?
Yes, the explicit occurrence of '#%app' in the template is replaced. And
it affects the '(3 5)' application, because that's in the *body* of the
'let-syntax' form. The '(+ a b)' expression, however, is in the
*right-hand side* of the 'let-syntax' expression, which is not in the
scope of the new '#%app' binding. Instead, it's in the scope of the
binding of '#%app' as a pattern variable (via 'with-syntax').
(define-syntax (blah stx)
(syntax-case stx ()
((_ exp)
(with-syntax
((#%app (datum->syntax-object #'exp '#%app)))
#'(let-syntax ((#%app ;; <-- this binding of '#%app' is ...
(syntax-rules ()
((_ a b) (+ a b))))) ;; <-- not in scope here
exp))))) ;; <-- in scope here
>> In this case, the reference to '#%app' is implicit. And if it were
>> explicit, it would be substituted away as a pattern variable. So it's
>> an unusual case. My advice would be not to use the implicit syntax
>> names (like '#%app', '#%datum', '#%top') as pattern variable names.
>>
>
> *blinks* is this a matter of timing? ie, when the implicit #%app is
> "explicited"?
Yes.
> If so, why does version #1 work at all? That is, why wouldn't the same
> principle cause the implicit #%app in the first version to see the
> standard #%app rather than the locally introduced one?
Yes, and it does.
(let-syntax ((#%app
(syntax-rules ()
((_ a b) (+ a b))))) ;; <-- standard #%app
(3 5)) ;; <-- new #%app
After all, you do want to really apply the '+' procedure to those
arguments; you have to get to core syntax eventually.
> And again, thank you.
You're welcome.
Ryan