How do you unbind variables in an interactive Erlang session?
Asked Answered
T

2

27

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?

Taxidermy answered 24/3, 2010 at 21:12 Comment(0)
L
44

Use the built-in functions 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

Leaky answered 24/3, 2010 at 21:21 Comment(0)
T
2

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.

Thematic answered 25/3, 2010 at 18:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.