29

I'd like to know if there is a REPL which is not language-specific. I spend a lot of time dipping in and out of REPLs (mainly for Clojure, Scala and Haskell), and the bundled ones all frustrate me to a greater or lesser extent. It seems like the job of a REPL is quite generic in that they:

  • Read: take user input
  • Evaluate: pass the input to some runtime for processing
  • Print: print the results to the screen
  • Loop: wait for the next user input

I don't see why there shouldn't be some language-agnostic REPL, but I have been unable to find such a thing. Some things I would like in my ideal REPL:

  • Linux command-line application
  • Infinite history accessible through the up arrow
  • Ability to edit previous commands before re-running
  • ctrl-r for history search like bash has
  • Multiple sessions in one REPL, so I can switch between them easily

And more optimistically

  • syntax highlighting, context-aware code completion

Does this exist?

Matthew Gilliard
  • 9,298
  • 3
  • 33
  • 48
  • 6
    All Emacs REPL modes are built on top of comint mode, so they tend to be very similar to each other. Naturally they support history, and code completion (where appropriate). – dfan Apr 12 '11 at 17:58
  • 2
    You have conflicting requirements here: you want a REPL which at the same time doesn't know anything about the language and yet somehow magically has intimate knowledge about the language in order to provide code completion. – Jörg W Mittag Apr 12 '11 at 23:03
  • 3
    I don't see these as conflicting. I want a REPL which presents a uniform interface to any number of backends. Language-aware stuff would have to be pluggable, that's all. – Matthew Gilliard Apr 13 '11 at 13:59

3 Answers3

34

Bash doesn't know anything about C-r: it uses readline, which does that, as well as up-arrow history, for it. It sounds like the REPL you're looking for is readline? Just prefix the command you want REPL-like behavior from with rlwrap (install it if you don't have it - it's great), and you should be good to go.

$ rlwrap java -jar clojure.jar
amalloy
  • 89,153
  • 8
  • 140
  • 205
  • OK This works nicely for the clj repl, but doesn't give me ctrl-r in the scala repl for some reason. Looks like ghci already uses readline, so thats nice. Edit: actually this makes a *tremendous* difference to the clojure repl - thanks! – Matthew Gilliard Apr 12 '11 at 19:19
  • +1 for rlwrap: I started using it for learning clojure and it has made it much more fun – coder_tim Apr 12 '11 at 20:42
  • This appears to answer the ctrl-r bit but not the REPL bit. You're just adding readline to a command that already does repl. – Tim Abell Jan 25 '16 at 22:21
5

Scala 2.9 REPL will have CTRL-R reverse search support. The nightly builds have that already. There has been context aware tab completion for a while (though it could be improved).

When using scala with rlwrap, use the -Xnojline flag:

rlwrap scala -Xnojline

That prevents jline from interfering with rlwrap. Then rlwrap is free to use readline to implement cursor motions and history but that is before the interpreters sees the line and you won't have language-aware completion.

I hope that the Scala REPL will be improved.

  • There is a presentation compiler that is part of 2.9 which I think is used for things like highlighting errors and completion.
  • The jline used by scala 2.9 is capable of using ansi colors leveraging jansi

So I can dream that one day I will have IDE level feature in the Scala REPL. Realistically, it would require substantial effort and adding these features is surely lower priority than improving eclipse support for instance... Besides it may make more sense to add REPL support in eclipse.

huynhjl
  • 41,520
  • 14
  • 105
  • 158
  • This appears to answer the ctrl-r bit but not the REPL bit. You're just adding readline to a command that already does repl. – Tim Abell Jan 25 '16 at 22:21
2

While not strictly speaking a REPL, Seco offers a notebook-style shell that can evaluate expressions in any language with a JSR-223 binding. This rapidly growing list includes languages like Javascript, Scheme, Python, Ruby, Clojure, Groovy and Prolog.

Seco's inspiration, the Mathematica notebook front-end, can in principle evaluate expressions in any language although it takes some work to make that happen.

Community
  • 1
  • 1
WReach
  • 18,098
  • 3
  • 49
  • 93