Line and command numbering in REPLs

A REPL session is a sequence of commands, where each command is one or more input lines (usually typed by a human), followed by the output of the result of evaluating the input lines. The output can be zero over more text lines, but some envionments allow printing images, graphcs, or rich text. While typically each command is a single line, sometimes commands may span over multiple lines. This note discusses pragmatics of numbering those lines and commands, and recommends that command numbers be identical to line numbers.

The most important reason for wanting command or line numbers is for error messages. Errors when compiling or loading a file generally have the form of a file name, followed by a line number (optionally a column-number or a range), possibly some identifying information (an error code or type), followed by a human-readable message. It makes sense to use the same form for REPL error messages. Run-time errors (or debugger break-points) may include a stack trace that references a similar file+line position.

Prompt number and eror messages

Suppose you want to work with hexadecial literals, which in Scheme have the prefix #x:
#|kawa:1|# #xff

(The default comment in Kawa Scheme has the form of a comment, to better support copy-and-paste. The color scheme will be discussed later.)

The next command spans two lines and has invalid charaters in the hex literal:

#|kawa:2|# (+ #xff
pcont #xabcdefg)
errloc: excess junk after number

We have inter-related questions: What should be in the continuation-line prompt pcont? How should the location in the error message errlc? Should the number of following command N be 3 or 4?

When numbering commands

stdin2:2:10: excess junk after number

references to previous commands (history)

When numbering lines

First, my recommendation as implemented in Kawa, which is to number lines (rather than commands):

#|kawa:2|# (+ #xff
#|.....3|# #xabcdefg)
stdin:3:10: excess junk after number

Smart input/output interleaving

Consistency with sourcing a file

Display the output

In most IPython or Jupyter front-ends prefix each input command prefixed with a prompt In[number], but additionally (first) output line is redundant prefixed with Out[number], which means less space is evailable for the output. (Also, the output is indented, which may mess up display of TAB characters, unless care is taken.) Sometimes, for multi-line or graphics output the Out[number] missing. Better and more consistent is to always leave off the Out[number]; it doesn't provide any extra information.

IPython/Jupyter front-ends also tend to leave quite a bit of whitespace between commands, which slightly improves visibility, but wastes valuable screen spaces. I suggest instead DomTerm use of a thin dashed line, which provides a clear demarkation between commands while using less space:

#|kawa:2|# (fill 'green (circle 30))