erl: the interactive shell
| Start erl | |
| Evaluate expressions | |
| Shell helpers | |
| Recall results |
Start erl
Run erl with no arguments to start a local shell. The prompt counts up from one, and every answer comes back as a value you can use in the next line.
erl
Eshell V15.2 (abort with ^G)
1>
Type an expression and end it with a period. The shell prints the value and its type hint, then waits for the next one.
Evaluate expressions
Every expression ends with a period. The shell prints the value and its type hint, then waits for the next one.
Strings print as lists of character codes unless you ask for a readable form, which lesson 40 covers.
1> 1 + 2.
3
2> hello.
hello
3> [hello, world].
[hello,world]
4> help().
2> h().
3> q().
1> 1 + 2.
3
2> hello.
hello
3> [hello, world].
[hello,world]
Shell helpers
The help function lists the shell commands. The h function shows the history, and q halts the node cleanly.
1> help().
2> h().
3> q().
1> 2 + 2.
4
2> % * 10.
40
3> v(1).
4
Recall results
The percent sign recalls the previous result, and percent with a number recalls that numbered result. Both work in any later expression.
The v function returns a stored value instead of printing it, which is handy inside a longer line.
1> 2 + 2.
4
2> % * 10.
40
3> v(1).
4
Next: Your first Erlang script
Article author: Arthur Isaev