
Improve your REPLs with rlwrap - telemachos
http://ithaca.arpinum.org/2013/01/20/rlwrap.html
======
larsberg
This program is exactly what we usually recommend for people who aren't using
SML/NJ inside of an Emacs inferior window (which is far and away the most
common usage mode for experienced SML/NJ programmers - all ten of us <grin>).

I personally apologize for my laziness. Two or three different times I've
started in on making something similar to the haskeline package in GHC to
provide readline-style support to make life easier for students, but have
never quite finished it up. Unfortunately, "just linking" readline/libedit
isn't a very friendly solution given the way that the interpreter is currently
architected, as it's written on top of the ML basis library primitives for
reading/writing individual characters from the input stream.

~~~
telemachos
Thanks for mentioning Emacs: You made me realize _why_ this hadn't come up in
the course notes or material for the Coursera class I'm doing[1]: they
explicitly recomment using SML inside Emacs. Unfortunately, I'm a relatively
long-time Vim user, and I'm just not comfortable editing in Emacs. So I came
to this round-about solution.

[1]: <https://class.coursera.org/proglang-2012-001/class/index>

------
jackalope
I've been using rlwrap for years with Oracle's sqlplus command line client on
Linux.

Because it uses readline, it can benefit from settings in ~/.inputrc, along
with all of your other readline-based applications for a more uniform
experience.

For example, I'm a vi(m) user, so I put this in my .inputrc:

    
    
        set editing-mode vi
    

That's just the tip of the iceberg.

These days, I tend to use the dbext vim extension for Oracle queries, allowing
me to develop and save them in one file per project. But when I need to fire
off something quick on the command line, it's nice to have rlwrap available.

~~~
minimax
The command line SQL client is one place Postgres blows away Oracle. I'd pay
real money for psql on Oracle.

~~~
loeg
You would have to, wouldn't you? It's Oracle...

~~~
minimax
Not at all. There are several free open source alternatives to sqlplus like
Yasql and sqlpython but none of them are as good as psql.

------
Inufu
This is great, exactly what I needed for the new Coursera class about
Programming Languages:
<https://class.coursera.org/proglang-2012-001/class/index>

(They start of with ML and a very simple REPL)

~~~
telemachos
I'm taking the same course. I was frustrated with the SML REPL, learned about
_rlwrap_ and wrote this up. Glad it helps. (I just posted the tip to the
course's forums as well. Thanks for reminding me.)

~~~
prezjordan
Thanks for your contribution! What do you think of the course so far? I had
too much fun doing the first homework.

~~~
telemachos
ML itself is interesting, and I think the material for the class is good. I
enjoyed the first round of homework - not too easy, but not really too hard
either. The tough thing for me will be seeing whether can I maintain the extra
work for the full 10 weeks.

------
wging
OS X users, I advise using

    
    
        brew install rlwrap
    

instead of downloading the tarball in the link. You may feel tempted to
download a tarball and compile readline. But I experienced the problem
mentioned in rlwrap-0.37/BUGS:

    
    
        49-On recent OS X sytems, libreadline is not the real thing, but a
        50-non-GNU replacement. If the linker complains about missing
        51:symbols, install GNU readline and try again.
    

This may then lead you to attempt compiling and installing GNU readline, which
will ultimately lead you to try to solve more problems you're having in
compiling readline. You might find this fun. But if you just want to get
things over with, there is an easier way. Homebrew[1] to the rescue:

    
    
        brew install rlwrap
    

Perhaps this is just obvious to others. Would've saved me a few minutes to
hear this, though.

[1]: <http://mxcl.github.com/homebrew/>

~~~
telemachos
I definitely think a package manager is better than manual installation.
That's why I said this:

> Simply install rlwrap via your operating system’s package manager (or
> manually)

But I'll add an update that mentions the bug on OSX. Thanks for the feedback.

~~~
wging
Ah, you're right. Sorry for implying you didn't mention this. I overlooked
that--just went to the rlwrap page and got caught up in what I was doing.

~~~
telemachos
No worries at all. Any feedback is good - and I added a clarification to make
it's clearer now.

------
malandrew
For the rlwrap gurus in the thread, is there a way to use rlwrap to better
deal with multiline expressions in the repl?

For example, when using a clojure repl and entering a multiline expression, I
might err on one line and want to go back and correct that line before
evaluating the expression. Unfortunately, the only option I have right now is
to terminate that expression by entering in a bunch of closing parens and then
trying to enter in the entire multiline expression again. It'd be great if
multiline expressions could be modifiable and if you could up arrow to load a
previous multiline expression.

~~~
stinkypete
You might try starting rlwrap with the `-m' option (--multi-line) which by
default escapes " \ " into newlines. By itself this isn't all that useful but
this enables editing the line in your $EDITOR via `ctrl-^'. When you do this
the editor will display the escape sequences as literal newlines, so that
means you can do multi-line editing with up to recall a previous expression
and `ctrl-^' to edit it.

If you're to the point where you are editing lots of multiline expressions you
may want to consider using an editor that has a function that will send the
contents of a buffer or the current expression to a running interpreter. Emacs
is an obvious choice for this, but there are lots of plugins to other
editors/IDEs that do the same.

------
6ren
I just want to say that rlwrap is awesome.

Such a _simple_ idea, yet so effective.

------
niggler
rlwrap seems cool at first blush, but you quickly realize that for anything
nontrivial (e.g. context-aware autocomplete) you need to use readline directly

~~~
snprbob86
This isn't about adding readline support to your own programs (although it's a
reasonable stop-gap solution there), this is about adding basic readline
support to _other people's_ programs without a massive investment.

------
pi18n
I knew about rlwrap, but hadn't bothered to learn anything in depth. Thanks,
keywords are a great feature that I wouldn't have known without this.

------
shitlord
For people who like ruby but think irb sucks, there's pry
(<http://pryrepl.org/>), but it's still missing some features.

~~~
banister
which features is pry missing?

------
prezjordan
This is a godsend, thank you! I've been having a tough time using `sml` and
`gprolog`, but this fixed every single issue I found. Thumbs up.

------
toolslive
ocaml has an awful default interpreter repl, so most people use it with emacs.
Alternatively, my default rlwrap is this:

rlwrap -p"0;31" ocaml -init _init.ml

the -init allows me to preload, set directories aso.

As a remark on the side. A lot of people complain about a lot of things
without even bothering to improve the quality of their working environment.

------
Syssiphus
News at 11'

