sml Interactive Programming using the REPL Starting the SMLNJ REPL


Example

REPL stands for 'Read Evaluate Print Loop.' The REPL can be used to write and execute code one line at a time and is an alternative to writing code to a file and then compiling or interpreting the entire file before execution.

To start the SMLNJ REPL from a command prompt:

smluser> sml
Standard ML of New Jersey v110.78 [built: Thu Jul 23 11:21:58 2015]
- 3+4;
val it = 7 : int
- (*a comment: press contrl-d to exit *)
smluser>

In the Bash and similar command shells, GNU readline functionality can be added to the SML REPL using the system command rlwrap sml.

smluser> rlwrap sml
Standard ML of New Jersey v110.78 [built: Thu Jul 23 11:21:58 2015]
- 3+4;
val it = 7 : int
- (* pressing the up arrow recalls the previous input *)
- 3+4;
val it = 7 : int
-
smluser>