[plt-dev] language dialog, some minor changes & bugfixes

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Jan 29 15:24:07 EST 2010

On Jan 29, Eli Barzilay wrote:
> On Jan 29, Robby Findler wrote:
> > - The "Language: ..." line in the interactions window now says
> > something approximately correct. It should use the read-language
> > infrastructure to get the name of the language, but I don't see
> > how to do that. Any tips would be appreciated. Meanwhile, it just
> > looks at the first line of the window and drops "#lang" (if it
> > appears).
> 
> (I'll hack something quick in a second.)

Here's some rough code that is easy to translate to a port instead of
a string:

  (define (lang-line str)
    (let* ([i (open-input-string str)]
           [l (read-language i (lambda () '?))])
      (if (eq? '? l)
        (values "???" '???)
        (values (regexp-replace #rx"^#(?:!|lang ) *"
                                (substring str 0 (file-position i))
                                "")
                (l 'module-language '???)))))

You probably need just the first value, the second one is more of a
demonstration...

[The second value is probably not what you need -- it's supposed to be
the actual language module that is used in the (module ...)
expression, which is sometimes not something that the user is aware of
(try (lang-line "#lang scribble/text")) and sometimes it's not there
because the lang-info protocol is too new (try (lang-line "#lang
scribble/doc")).]

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the dev mailing list.