Combining code editing with a command line
Update 2012-09-05: separated input and output.
The name is derived from the abbreviation REPL (read-eval-print loop) that is a common synonym for “command line” in the functional world. Node.js uses that term, too .
How does jsrepl work?
Input and output are handled by separate text areas. The input area is used like a normal text editor, so the Return key inserts line breaks. If you want to evaluate expressions or statements, you have two options:
- Multi-line evaluation: select text and hit Shift-Return.
- Single-line evaluation: place the cursor in the line you want to evaluate and hit Shift-Return. If the cursor is at the end of a line, a newline will inserted.
Other than inserting a newline in case (2), the input area remains unchanged when you hit Shift-Return. The result of the evaluation is inserted at the end of the output area. console.log
output and exceptions show up there, too.
Var declarations and function declarations work, but I had to use hacks to make them work , so you might not always get the results you expect.
jsrepl has been inspired by the Macintosh Programmer’s Workshop
, which I have never used, but read about a long time ago (mid 1980s). There must be other prior art, too (Smalltalk, Lisp, ...).
- Execute code each time the Node.js REPL starts