How to 'fix' the SML/NJ interactive system to use Arrow Keys - sml

I'm having some trouble using SML/NJ interactive system, namely, that when I try to use my arrow keys (either left or right to make a correction in the expression I've typed, up to repeat the last expression), my Terminal prints codes. (e.g. ^[[A for up^[[D for left, etc.). While I can still use the system, it makes it very tedious.
I've looked around in Control.Compiler, is there something I'm missing? For whatever its worth, I'm using the Mac Terminal.
Thanks ^_^

Another option is rlwrap.
rlwrap sml

Try this. You can use socat to add readline support to many things:
socat READLINE EXEC:sml
I just realized you're on OS X. socat does seem to be available for OS X, although I have not tested it (this does work on Linux).

Related

list of SML/NJ REPL commands

I'm looking for a full list of commands like Ctrl-Z that work in the SML/NJ REPL. I've searched here, Google and the SML/NJ website but can't find anything, not even the ones I already know.
To be clear, I'm not looking for an SML language reference, just the REPL interface commands.
Ctrl-Z (under Windows I assume) is not necessarily a SML command. It rather colses the console instance. It means End-Of-File. Under Win you can see a simple application of this behavior by using:
copy con text.txt
This copies characters from the keyboard (con) to the text file. Many REPLs just use the same mechanism/understanding.
Largely the same exists under Unix/Linux systems with Ctrl-D.
Coming from here, there might be no more REPL commands for SML/NJ.

Netbeans - copy highlighted regex search results

I made a simple regex search in Netbeans 7.3 on Windows (using Ctrl+F):
\{\{.*?\}\}
The results get highlighted correctly and the question is - how to extract highlighted text search results? Let it be copying to clipboard, saving as file or whatever else.
Is there any method doing this?
Maybe someone has any suggestion of alternative quick approach to such task in Netbeans? (or other editor)
What OS are you running? If OS X or Linux, read on!
I'm not sure about automatically copying the highlighted results to the clipboard, but I do workaround this quite a bit as well.
The easiest way to accomplish this for me without leaving NetBeans is to simply open a built in terminal window through Window>Output>Terminal (in 7.2.1) - I then navigate to my project, and run the RegEx that I built in the Find feature with my tool of choice. In fact, I use the built in terminal for this type of quick stuff in NetBeans quite a bit. If running Linux, using clipboard tools like xsel (http://linux.die.net/man/1/xsel) in combination with a built in terminal emulator can allow for devising some nice workflow shortcuts within IDEs if you are more comfortable working/coding at a terminal. Note that built in terminal emulators like the one in NetBeans is likely not going to play nicely with cut/copy/paste using the mouse, for various reasons that I won't get in to here.
As far as a built in/extension based solution for something like this, it would be helpful! I am not aware of one.
Hope this workaround helps in the meantime.

Find what was printed in the terminal

Is there anyway to check the terminal (Linux, and Windows) for characters at certain positions? I have external methods loaded via an explicitly loaded dll that prints certain characters onto the screen. I need to see if the functions printed what they were supposed to with minimal cross talk between the between the plugins. So at the core I am wondering if C++ has any feature for pulling chars off of the termial/command line?
This is not possible on VT100-like terminals (the kind popular in Linux.)
For Windows I can't say, but if you are using a cygwin terminal (not the power shell or the "DOS shell") the answer is again no.
You could use tmux or screen to set up a virtual terminal. The display state can then be captured, which seems to be what you want. But something in my brain is telling me that, whatever you are trying to do, this is probably not the right solution. What exactly is your problem?

how to repeat last command in OCaml interpreter shell

I've been trying out OCaml. Sometimes its quicker just to test out some code using the interpreter shell but, it doesn't bring up the last command when I press the 'up' key.
Its a pain when I miss type something or wish to see what a little variation would produce.
Anyone know if there is another key for it?
Thanks,
Use rlwrap:
rlwrap ocaml
ocaml itself has no readline support.
You can configure readline using ~/.inputrc.
For example, you could add such lines to it:
$if ocaml
"\C-o": "()\C-b"
"\C-n": ";;\n"
$endif
Now you can use ctrl-o and ctrl-n hotkeys in ocaml. Just try it.
You can use the improved toplevel utop.
Moreover, it includes nice completion capacities.
I used ctrl + arrow up for previous input

Easy ways to try out and test Lisp syntax?

Clojure has introduced me to the concept of Lisp syntax, and I'm interested, but it's a pain to get the Clojure repl set up and use it on different machines. What other resources are there out there for actually on-the-fly testing and playing with Lisp syntax?
I'm imagining something like a website where you can input rudimentary code, or a browser add-on, or even just a standalone application that steps you through Lisp (something that runs on Linux/Ubuntu).
Haven't been able to find anything like that to start me off in a simple/accessible way.
The SISC Online REPL is exactly what you need. It accepts Scheme syntax, which is a variant of Lisp.
For a standalone app I like PLT Scheme because it seems to work the same on every platform I've tried. I was previously using MIT Scheme on Ubuntu, but decided to switch when I bought a new machine with 64-bit Vista installed.
At the risk of losing all of my rep points, try newlisp.
I've used LispBox in the past. Easy to set up and get going, but I have to admit that Emacs is second nature to me. If you're unfamiliar with that, you may can use another editor, but getting intimate with Emacs will help you live comfortably in Lispville.
It's not hard to get to a Clojure REPL nowadays.
Go to http://build.clojure.org/ and download clojure.jar.
Install a JVM.
java -jar clojure.jar
This should work on any machine that has a JVM installed.
For more fun, install rlwrap and use rlwrap java -jar clojure.
For learning Lisp the LispWorks personal edition is fine: LispWorks downloads. There are versions for Mac OS X, Windows, Linux and FreeBSD. All have the same user interface capabilities and this includes an editor and listener - plus lots of other tools. On Linux and FreeBSD in currently (LispWorks 5) uses X11/Motif for the GUI - this will change in a future version (LispWorks 6) to GTK. So to run it now under Linux, you need to have the Motif lib installed. Other than that using it is relatively painless. There are some restrictions to it (only 5 hours runtime, then you need to save and restart, ...) and the full version is commercial. But for learning some Lisp basics, it is quite good.
Franz has an online REPL for Allegro Common Lisp.
http://www.franz.com/products/allegrocl/prompt/
codepad.org is a nice simple online way to enter and run code (in many different languages, including Scheme). I use it all the time for testing out snippets of code to use in SO answers.
I won't edit Lisp code without an editor that does what Emacs will do with the following configuration:
(define-key lisp-mode-shared-map "[" 'insert-parentheses)
(define-key lisp-mode-shared-map "]" 'move-past-close-and-reindent)
The former inserts balanced parentheses. If you give it a numeric prefix argument, it inserts that many nested pairs. By default, it inserts one. If you have a text region marked, it encloses that region in the innermost inserted pair. That means that you'll never open a parenthesis that's not closed.
The latter is harder to explain, as it's used less frequently. It's more of a navigation command than an insertion command. It confirms that you're done editing the current form and moves the cursor up, out, and past it, preparing for the next likely insertion.
With these keys bound, one no longer needs to use the Shift key to access the parentheses. Also, this leaves the parentheses keys bound as normal, for when sexp repair or a literal parenthesis character is required. I stole the bracket keys because they're used so infrequently in Emacs Lisp and Common Lisp. The bracket characters are still accessible with meta key bindings:
(defmacro make-key-inserter (def)
"Substitute for `self-insert-command'."
`(lambda (arg)
(interactive "*P")
(insert-char ,def (prefix-numeric-value arg))))
(define-key lisp-mode-shared-map "\M-[" (make-key-inserter ?\[))
(define-key lisp-mode-shared-map "\M-]" (make-key-inserter ?\]))
It's not essential to use Emacs, but don't settle for less with another editor that can't at least match this capability. There's also a whole family of commands for navigating and manipulating the sexp tree as a tree. Understanding why that's valuable will require you to fumble around for a while until you stop seeing syntax and start seeing the tree.
Since you're using Ubuntu, I'd just install some of the packages and give them a try.
Common Lisp: apt-get install clisp
Scheme: apt-get install drscheme
These aren't the only packaged implementations, but maybe the easier to get started with. You'll be able to play at a REPL and also run your own scripts through the interpreter.
BioBike provides a full Common Lisp evaluator through the web (with extras like a knowledge representation system, biocomputing, and an alternative visual langauge as well).
If you just want to play with LISP, interactively, quickly, GNU Emacs has a LISP interpreter built in, and listening in the *scratch* buffer. Type an S-expression, position immediately after it, and then hit Ctrl-J to evaluate it. Or <ESC>: will put an Eval: prompt in the minibuffer, accept an S-expression, and evaluate it.
You can define functions, using defun, and test things that way. You have access to ALL of the GNU Emacs built-in functions, and anything you have loaded. If you want to keep things around, you can put them in your .emacs file.
https://github.com/fogus/himera
was very easy for me to setup on a https://www.nitrous.io virtual box. Makes a nice web interface.
Downloading and running clojure-1.6.0.jar on my windows (XP) box was as easy as using this script to run the REPL :
java -cp clojure-1.6.0.jar clojure.main