Command-line REPL for a custom #lang?

85 views
Skip to first unread message

Alexis King

unread,
Jun 3, 2016, 6:28:32 PM6/3/16
to dev
Currently, it does not seem like there is any option to open a new
command-line REPL for a particular #lang. Based on what already exists,
I’m not sure if this is a bug or if it’s intended (or perhaps
overlooked) behavior.

The -I command line flag to the racket executable states that sets the
<init-lib>, with a note explaining that it sets the language. This is
not quite true, however: it appears to do more than simply requiring the
module into the top-level namespace, but it’s not setting the #lang —
instead, it seems to simply open a REPL as if you started a REPL in
DrRacket inside the specified module.

This sounds similar, but it’s not: if I have a language called “foo”,
implemented in foo/lang/reader, then run `racket -I foo`, the module
that is required is just foo, not foo/lang/reader. This means that the
language used is actually whatever #lang is present in the foo module,
which might not be #lang foo at all — it might be racket/base, or even
anything else. Interestingly, this is the case for typed/racket/gui:
using typed/racket and typed/racket/base works with the -I flag because
they are implemented using the typed-racket/minimal language, but using
typed/racket/gui does not enable the #{x : T} reader syntax because it
is implemented with racket/base.

It seems like it would be valuable to either make -I do what I think its
description would cause most people to expect or to add another option
that is just like running a REPL in DrRacket in an empty module with a
particular #lang line. I’d guess it might be a good idea to make it a
separate flag, since I could imagine the behavior of -I being used
intentionally, so maybe another flag? Is there some other way to achieve
this behavior with the current set of options that I don’t know about?

Alexis

Ben Greenman

unread,
Jun 3, 2016, 6:52:54 PM6/3/16
to Alexis King, dev

On Fri, Jun 3, 2016 at 6:28 PM, Alexis King <lexi....@gmail.com> wrote:
Is there some other way to achieve
this behavior with the current set of options that I don’t know about?

One idea: define a raco command to open the repl.


[[ Assuming you make a package out of #lang custom,
   you'd want to add a line like this to your `info.rkt`:

  (define raco-commands '(("custom" (submod custom main) "Open a REPL" #f)))

  Then, inside the `main.rkt` file, add a submodule:

  (module+ main
    (require ...)
    (run-repl ...))

  Where `run-repl` is a function that starts an interactive session. ]]
Reply all
Reply to author
Forward
0 new messages