[racket] examples of hooking a #lang into DrRacket?

From: Matthew Butterick (mb at mbtype.com)
Date: Mon Jul 21 14:23:51 EDT 2014

I can confirm that when I add a get-info function to the Pollen reader, it does work as expected in DrRacket. So perhaps Pollen doesn't "need" to change, but it will ;) Thank you for the help.

FWIW here's the accumulation of stumbles that led to my mistake:

+ AFAICT the #lang tutorial in the docs refers to get-info but not read-language. [1] Thus I never knew that read-language existed or what it did.

+ Based on the tutorial example [1], I had incorrectly concluded that get-info was an arbitrary private name, rather than a special name sought by read-language. 

+ I also didn't appreciate that get-info is mandatory for proper DrRacket compatibility, not optional.

+ (get-info, of course, is also the name of a function in setup/getinfo [2])
 
+ When there is no get-info function, DrRacket visually suggests that an error has occurred (red #lang line, no toolbar buttons) but doesn't print the actual error in the window (creating mystery)

+ You say that DrRacket doesn't cache any #lang information at startup. For whatever reason, I continue to find that relaunching makes a difference (i.e., if the #lang doesn't provide get-info at the beginning of a DrRacket session, adding one *during* the session will not fix the error; it will be noticed only on relaunch). I can't account for this behavior, but I can reliably reproduce it. This issue tripped me up, however, as it made it seem that get-info was not making a difference, so I eliminated it as the solution too soon.



[1] http://docs.racket-lang.org/guide/language-get-info.html?q=%23lang&q=read-language

[2] http://docs.racket-lang.org/raco/getinfo.html?q=get-info&q=%23lang&q=read-language#%28def._%28%28lib._setup%2Fgetinfo..rkt%29._get-info%29%29



On Jul 20, 2014, at 6:21 PM, Robby Findler <robby at eecs.northwestern.edu> wrote:

> Yeah: I think that it is safe to say at this point that pollen doesn't need to change. Either read-language's docs (and various places in DrRacket and libraries) need to change or read-language needs to change and either way pollen will work afterwards. 
> 
> My guess is that your language is the only one that doesn't define a get-info function itself but I can't check that theory right now. 
> 
> You can probably make pollen work now by supplying a get-info proc that always returns the default value. (See the third and subsequent paragraphs here: http://docs.racket-lang.org/reference/Reading.html?q=read-language#%28def._%28%28quote._~23~25kernel%29._read-language%29%29 ).
> 
> Robby
> 
> On Monday, July 21, 2014, Matthew Butterick <mb at mbtype.com> wrote:
> > It appears that read-language can return #f and what DrRacket does in
> > that case appears to be what you're seeing. Is that what you're
> > getting?
> 
> Your theory seems correct. Yes, Pollen is the only #lang returning #f for read-language, e.g.:
> 
> #lang racket/base
> (map
>  (λ(lang) (read-language (open-input-string (format "#lang ~a" lang))))
>     '(racket racket/base scratchy scribble/manual scribble/text rackjure pollen))
> 
> '(#<procedure:language-info>
>   #<procedure:language-info>
>   #<procedure:...atchy/reader.rkt:26:2>
>   #<procedure:language-info>
>   #<procedure:language-info>
>   #<procedure:language-info>
>   #f)
> 
> 
> Moreover, if I use your main.rkt, it triggers the same problem in DrRacket (#lang line is red, no toolbar buttons)
> 
> But beyond the issue of whether the docs or DrRacket is doing the right thing with the #f value, I'm unclear why Pollen is returning #f for read-language. One possibly unorthodox thing I'm doing here is that my #lang files rely on macro expansion. For instance, here's Pollen's main.rkt:
> 
> 
> #lang racket/base
> (require pollen/main-base)
> (define+provide-module-begin-in-mode world:mode-preproc)
> 
> (module reader racket/base
>   (require pollen/reader-base)
>   (define+provide-reader-in-mode world:mode-auto))
> 
> 
> ... where `define+provide-module-begin-in-mode` is a macro that creates the #%module-begin macro, and `define+provide-reader-in-mode` is a macro that creates the reader.
> 
> This doesn't bother DrRacket when the file is being run, but perhaps this approach is incompatible with either read-language, or DrRacket's #lang validation?
> 
> 
> 
> 
> 
> On Jul 20, 2014, at 4:50 PM, Robby Findler <robby at eecs.northwestern.edu> wrote:
> 
> > It appears that read-language can return #f and what DrRacket does in
> > that case appears to be what you're seeing. Is that what you're
> > getting?
> >
> > The docs say that read-language never returns #f (presumably it is
> > allowed to return #f when fail-thunk returns #f, but the relevant
> > fail-thunk here doesn't return #f) so I'm not sure if that's a docs
> > bug, in which case I should change drracket to cope with it or an
> > implementation bug.
> >
> > But if I create a pollen directory, use 'rack pkg --link pollen' to
> > set it up and then put main.rkt with this content:
> >
> > #lang racket/base
> > (module reader racket/base (provide read-syntax)
> >  (define (read-syntax a b)
> >     #'(module m racket/base)))
> >
> > then I see this:
> >
> > $  racket
> > Welcome to Racket v6.1.0.3.
> >> (read-language (open-input-string "#lang pollen"))
> > #f
> >
> >
> > Robby
> 
> 
> ____________________
>   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/20140721/f8d41d26/attachment.html>

Posted on the users mailing list.