how to repeat last command in OCaml interpreter shell - ocaml

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

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.

Up arrow based command history in console input (C++)

I am trying to build a console application that takes user input. I was able to use printf to keep the cursor in the same place, I could have used curses as well, but I can't get up-arrow command history to work. Any pointers ?
I think you want readline (www.gnu.org/software/readline/ which seems to now redirect to the maintainer site at http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html)
In addition to the mentions of the readline library, I'll also mention the BSD-licensed editline library and the rlwrap command-line wrapper tool that runs any program with a readline-based history.
As long as the GNU license is not a problem for you, I would strongly consider GNU Readline
Have a look at the GNU Readline library. It can provide input history support.
In Windows the standard console windows provide up-arrow input history -- you don't have to do anything. For other standard Windows console services see the doskey command quickhelp, and simply replace the word "command" with "line of input". It's a bit misleading, yes.
EDIT, added para: Possibly you're doing something that circumvents the standard services. I just noticed that the browser window title says "ncurses", which is not in your current question title. Perhaps that's it, but in that case, ask specifically for help with ncurses.
For *nix see the other answers.
Cheers & hth.

Is there a plugin for Vim that would help me debugging like Visual Studio?

The reason why I'm asking this, is because I'm coding in C++, in putty/ssh and I like the fact that I can code from pretty much everywhere without having to install anything.
So I'd like to have something that could help me debugging (viewing LIVE value of a variable, breakpoints, etc)
If you think that there's no such thing in this world, is there any good technique I could use to debug in command line?
Thanks
I've used gdb for command line debugging in the past with success:
http://www.gnu.org/software/gdb/
A decent tutorial can be found at:
http://www.cs.cmu.edu/~gilpin/tutorial/
vimgdb will give what you want. I've used it for about one year. The most interesting feature is:
Hightlight current line
List item
Can show disassembly code
Step into, Step over
inspect variables, memory address
Run all the underlying gdb command is possible
And, of course, set breakpoint, conditional breakpoint etc.
Highly customizable by vim key mapping and scripts.
Actually I use checkinstall to make an rpm for it, and installed it everywhere when I need to debug on the box.
I think it have the most important features I want from a visual debugger.
Have you tried gdb ? That's pretty much the command line debugger, but it's no vim plugin.
You have a script to do that: http://www.vim.org/scripts/script.php?script_id=1954
In my humble opinion, Vim is not designed to do such things and it is a bad idea to do so.

Simple interactive prompt in C++

I work on an application that usually runs unattended. Now I need to add to it something like an interactive prompt. In the interactive mode the operator will be able to give simple commands to the application - nothing fancy, simple commands like start and stop. Parametrized commands (e.g. repeat 10) and commands history could be nice too.
Do you know, by chance, any library that helps with such tasks. I've been thinking about something that works like boost::program_options or gflags but for an interactive prompt and not for command line parameters. Any ideas?
Thanks
Readline is one the best known libraries for this
http://tiswww.case.edu/php/chet/readline/rltop.html
It is covered by GPL, so it is only possible to use in GPL-compatible programs.
I did a quick search for alternatives, and found this:
http://github.com/antirez/linenoise
I'm not sure if the following is a reasonable amount of work for what you're trying to do, but Python has a very nice Command Line Interface (CLI) building library called cmd2. If it's possible to expose the relevant parts of your apps to Python using SWIG or CTypes, then doing the rest should be easy.
Here's a nice video presentation about cmd2:
PyCon 2010:Easy command-line applications with cmd and cmd2
HTH
One possibilty is to open a TCP port and accept messages in text format. Then you can telnet to that port and issue simple commands.

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

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).