Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you unbind variables in an interactive Erlang session?

Tags:

In the Erlang interactive shell you can bind variables to values. If I would like to clear everything and start from scratch without exiting the session and starting a new one, how do I do that?

And if I just wanted to re-use a single variable, is it possible to re-bind?

like image 579
Torbjørn Avatar asked Mar 24 '10 21:03

Torbjørn


People also ask

Which function is used to exit the erlang shell?

JCL mode Once there you can use the command q to quit the Erlang shell. This is similar in effect to erlang:halt(0).

Which of the following is the correct syntax to define a function in the erlang shell?

Syntax − f(). For example − Following is an example of how the function is used. First a variable called Str is defined which has the value abcd.

How do I get to erlang shell?

On a Unix system you enter the command erl at the operating system prompt. This command starts the Erlang runtime system and the Erlang shell. On the Windows platform you normally start Erlang/OTP from the start menu. You can also enter the command erl or werl from a DOS box or Command box.


Video Answer


2 Answers

Use f() and f(Var):

1> A = 1, B = 2. 2 2> f(A). ok 3> A. * 1: variable 'A' is unbound 4> B. 2 5> f(). ok 6> B. * 1: variable 'B' is unbound 7> 

Shell commands are actually functions in the 'c' module: http://www.erlang.org/doc/man/c.html

like image 97
probsolver Avatar answered Sep 20 '22 11:09

probsolver


And if I just wanted to re-use a single variable, is it possible to re-bind?

Yes, when you "unbind" (f(Val) - forget) the value you can re-bind (match) it again. Needless to say it only works in erlang shell.

like image 22
Weasel Avatar answered Sep 19 '22 11:09

Weasel