[racket] How ought I run the annotate function in gui-debugger/annotator on a datum?
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.
On Tue, Jan 21, 2014 at 12:20 AM, John Clements
<clements at brinckerhoff.org>wrote:
>
> On Jan 20, 2014, at 4:40 PM, Patrick Boe wrote:
>
> > Thanks for taking a look, John. Here's a reduced version. I don't
> think there's any missing namespace information here at the time of
> evaluation, since the syntax is being manipulated in a macro, but I am
> relatively new to using namespace anchors, so I could be wrong. It seems to
> me like the syntax is being expanded either more or less fully than the
> annotator wants.
> >
> > #lang racket
> > (require (for-syntax racket/format gui-debugger/annotator))
> > (define-syntax fail-to-annotate
> > (lambda (stx)
> > (let-values
> > ([(annotated _)
> > (annotate-stx (expand (cadr (syntax-e stx))) '_ '_ '_ )])
> > annotated)))
> > (fail-to-annotate (string-append "hi" "lo"))
>
> Right... I would say "less." In particular, it appears to me that the
> syntax here is not fully expanded.
>
> However, this code is also setting off my "border-crossing" alarms. I've
> been working with the racket syntax since... 1997? ... and so it
> embarrasses me not to be able to give you a more definitive answer, but I
> think that, to make a long story short, you don't want to put calls to
> annotate-stx inside a macro. Instead, I think you probably want to
> implement your debugger the way the debugger does---as a global
> transformation on fully-expanded syntax.
>
> Put differently: doing it this way looks to me like it's straining the
> built-in structure of the macro system. You can probably move it toward
> what you want, but it's probably not ever going to work really nicely.
>
> Sorry for not giving you a more definitive answer,
>
> John Clements
>
>
> >
> >
> >
> > On Mon, Jan 20, 2014 at 2:18 AM, John Clements <
> clements at brinckerhoff.org> wrote:
> >
> > On Jan 16, 2014, at 4:05 PM, Patrick Boe wrote:
> >
> > > I am trying to learn how to use the DrRacket debugger's annotate
> function. My ultimate aim is to build a REPL that you can execute from
> within a closure and have access to everything that's in scope. (see my
> StackOverflow question on that topic and Greg Hendershott's well-researched
> answer) For the time being, I'm just trying to explore how the annotate
> function works. You can see my first exploratory attempt at using it, and
> the results, here.
> > >
> > > The error, which is happing inside of the annotator, seems to arise
> when it tries to pattern-match he application of string-append. The matcher
> is looking for a #%plain-app and the expanded syntax I'm presenting to it
> contains an #%app. I'm unsure if I should be expanding the syntax
> differently so it comes out as a #%plain-app or if there's something else
> I'm doing wrong to produce the syntax I'm feeding into the annotator. Does
> anybody see where my error is?
> >
> > Sadly, I don't have a browser right now, so I can't take a look at your
> links. Perhaps you can reduce it to a ten-line example? Could the solution
> have something to do with namespace anchors?
> >
> > John Clements
> >
> > >
> > > I originally posted this question to SO, but Greg suggested I might
> have more luck with it here.
> > >
> > > Best,
> > > Patrick
> > >
> > > PS - if you're reading this, thanks the great PLAI class last year, SK!
> > > ____________________
> > > Racket Users list:
> > > http://lists.racket-lang.org/users
> >
> >
> > ____________________
> > Racket Users list:
> > http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140121/d2662b27/attachment-0001.html>