[racket] How ought I run the annotate function in gui-debugger/annotator on a datum?
The documentation for `expand`:
http://docs.racket-lang.org/reference/Expanding_Top-Level_Forms.html#%28def._%28%28quote._~23~25kernel%29._expand%29%29
says:
"Expands all non-primitive syntax in top-level-form, and returns a
syntax object for the expanded form that contains only core forms,
matching the grammar specified by Fully Expanded Programs."
The documentation for Fully Expanded Programs:
http://docs.racket-lang.org/reference/syntax-model.html#%28part._fully-expanded%29
shows only #%plain-app -- _not_ #%app.
But when I try the example for `expand`:
(parameterize ([current-namespace (make-base-namespace)])
(syntax->datum
(expand
(datum->syntax
#f
'(module foo scheme
(define a 3)
(+ a 4))))))
I get:
'(module foo scheme
(#%module-begin
(define-values (a) '3)
(#%app call-with-values (lambda () (#%app + a '4)) print-values)))
Notice that it uses #%app -- not #%plain-app. Apparently `expand`
doesn't actually emit something that fits the spec for "Fully Expanded
Programs".
Guessing: Maybe the documentation -- and implementation -- of `expand`
predates the addition to Racket of keyword arguments? Probably there
is some extra expansion step, which creates the "lifted" #%plain-app
wrappers for keyword argument functions I recall seeing in DrRacket's
macro stepper?
But ... how does one access this "extra" expansion step??
On Tue, Jan 21, 2014 at 9:09 PM, Patrick Boe <patrickboe at gmail.com> wrote:
> Thanks, John.
>
> As you suggest, I'm trying to do exactly what the debugger is doing. As far
> as I can tell by tracing through its code, the debugger does the following
> to go from a raw datum ('(+ 1 2) in my example) to the syntax that it feeds
> into annotate (this is boiled down from several hundred lines of unrelated
> stuff in debug-tool.rkt)
>
> (expand-syntax
> (expand-syntax-to-top-form
> (namespace-syntax-introduce
> (datum->syntax #f
> '(+ 1 2)))))
>
> When I run this with racket from my command line, it fails with
>
> +: unbound identifier;
> also, no #%app syntax transformer is bound
> at: +
> in: (+ 1 2)
> context...:
> /home/patrick/dev/scry/scree.rkt: [running body]
>
> I can wrap it with a call to (parameterize ([current-namespace
> (make-base-namespace)]) ...), but then the resulting syntax is:
>
> #<syntax (#%app + (quote 1) (quote 2))>
>
> Which, as you can see, contains #%app instead of the #%plain-app that the
> annotator is looking for.
>
> Huh.