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

From: Matthew Butterick (mb at mbtype.com)
Date: Sun Jul 20 14:21:32 EDT 2014

That's a helpful clue, but DrRacket still seems to be making some kind of mysterious & negative judgment about the package when it starts up:


1) I created a branch in my github repo called pollen/scratchy that only consists of the file shown below, and switched to that branch.

2) Consistent with your result, when I launch DrRacket, '#lang pollen' is now black and buttons show up. Scratchy code works. That's promising.

3) With DrRacket still running, I switch my github branch back to pollen/master.

4) '#lang pollen' stays black, and buttons still appear, though now it's behaving as pollen. This is good news, but ...

5) ... when I quit DrRacket and restart (staying on pollen/master), '#lang pollen' is red once again, and no buttons. 

6) Moreover, switching to pollen/scratchy while DrRacket is running does not fix the problem.

7) But if I quit DrRacket again, staying with pollen/scratchy, and relaunch DrRacket, I return to the state described in step (2).


Sorry for the convoluted description. I'm curious if there's some extra package-validation step that DrRacket performs at startup that could account for this behavior, as that seems to be the pattern that triggers the problem. 




On Jul 19, 2014, at 11:05 PM, Robby Findler <robby at eecs.northwestern.edu> wrote:

> I did these steps:
> 
> "raco pkg install scratchy"
> mkdir pollen
> raco pkg install --link pollen
> cat <the code from your message> > pollen/main.rkt
> 
> and after that, drracket turns #lang pollen black for me.
> 
> Robby
> 
> 
> On Sun, Jul 20, 2014 at 12:48 AM, Matthew Butterick <mb at mbtype.com> wrote:
>> Still having some trouble with this:
>> 
>> When I use '#lang scratchy' in DrRacket, the #lang line is black and the DrRacket toolbar buttons show up, as they should.
>> 
>> After some trial & error, what I found is that if I simply change pollen/main.rkt to use the Scratchy parser and reader, like so:
>> 
>> ;;--------------------------------pollen/main.rkt
>> #lang racket/base
>> 
>> (require scratchy/scratchy)
>> (provide (all-from-out scratchy/scratchy))
>> 
>> (module reader racket/base
>>  (require scratchy/reader)
>>  (provide (all-from-out scratchy/reader)))
>> 
>> 
>> ... then '#lang pollen' invokes the Scratchy parser & reader correctly (= it will run sample Scratchy code).
>> 
>> Unfortunately the '#lang pollen' line still shows up in red, and there are still no DrRacket toolbar buttons (and still no error message in the bottom of the window)
>> 
>> Since a brain transplant hasn't fixed the problem, what else might DrRacket be looking for to validate '#lang pollen'?
>> 
>> 
>> 
>> On Jul 14, 2014, at 12:53 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
>> 
>>> The most relevant section of the documentation is
>>> 
>>> http://docs.racket-lang.org/guide/language-get-info.html
>>> 
>>> 
>>> The Scratchy language is intended to be an example:
>>> 
>>> https://github.com/mflatt/scratchy
>>> 
>>> 
>>> You could also check "reader.rkt" as part of
>>> 
>>> http://queue.acm.org/downloads/2011/racket/6-color/README.txt
>>> http://queue.acm.org/downloads/2011/racket/6-color/txtadv.rkt
>>> http://queue.acm.org/downloads/2011/racket/6-color/world.rkt
>>> http://queue.acm.org/downloads/2011/racket/6-color/lang/color.rkt
>>> http://queue.acm.org/downloads/2011/racket/6-color/lang/reader.rkt
>>> 
>>> which is from "Creating Languages in Racket" in "Queue". The
>>> "reader.rkt" module has the relevant part at the end:
>>> 
>>> ;; DrRacket asks `get-info' for a 'color-lexer module:
>>> (require racket/runtime-path)
>>> (define-runtime-path color-lexer-path "color.rkt")
>>> (define (get-info in mod line col pos)
>>>  (lambda (key default)
>>>    (case key
>>>      [(color-lexer)
>>>       (dynamic-require color-lexer-path 'color-lexer)]
>>>      [else default])))
>>> 
>>> The Scratchy example is more recent and I think better organized,
>>> though.
>>> 
>>> 
>>> At Mon, 14 Jul 2014 00:18:27 -0700, Matthew Butterick wrote:
>>>> Pollen source files run fine in DrRacket. But the `#lang pollen` line shows up
>>>> as red (though no error is reported in the bottom of the window) and no toolbar
>>>> buttons are available. So something is not quite right.
>>>> 
>>>> I gather that this has something to do with telling DrRacket about
>>>> language-specific capabilities. [1]
>>>> 
>>>> However, many of the custom #langs in Racket use the standard #lang s-exp
>>>> syntax/module-reader, which seems to eliminate these problems from the start.
>>>> 
>>>> Q: To supplement the documentation, are there particular #langs that show
>>>> examples of this kind of configuration file?
>>>> 
>>>> [1]
>>>> http://docs.racket-lang.org/tools/Language-Specific_Capabilities.html?q=Customiz
>>>> ing%20DrRacket%u2019s%20Behavior
>>> 
>> 
>> 
>> ____________________
>>  Racket Users list:
>>  http://lists.racket-lang.org/users



Posted on the users mailing list.