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.
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.
Thank you also for the mention of Emacs. After six years of using Emacs with a lisp REPL, where I could scroll back through function definitions and edit them in place, I feel distinct frustration every single time I use a Python REPL. One-line-at-a-time scrollback is absolutely frustrating.
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.
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.)
I suspected this might be the case. I'm in the same course, too, and I had never even heard of SML before it. I thought to myself, what are the odds of this showing up on Hacker News right now?
Many thanks, regardless! I upvoted your thread in the course general discussion, and I hope any other course takers on HN do to. It would be a shame if the non-hn course takers missed out on the thread (https://class.coursera.org/proglang-2012-001/forum/thread?th...).
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.
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.
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.
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.
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
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.
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.