Home > DeveloperSection > Forums > How to remove allocated value of a specific variable in Erlang?
Ashish Pandey

Total Post:128

Points:898
Posted on    March-09-2016 12:13 AM

 erlang erlang 
Ratings:


 1 Reply(s)
 241  View(s)
Rate this:
Can anyone tell me that if I bound the variable with incorrect value then how can I replace with another value.
for example: I have create a variable in Erlang shell:
> One = 2.          // by mistake bound wrong value in variable One.
2
> One = 1.          // if we again bound with new value then it generates error.
"exception error: no match of right hand side value 1"

So please tell me how to unbound any specific variable.
Thanks.


Tarun Kumar

Total Post:210

Points:1614
Posted on    March-09-2016 11:19 PM

The Variable which is already bounded then you can't bound it again. In Erlang operator (=) is used for pattern match not for initialization. But If the Variable is unbound and we use operator (=) then data on the right-hand side will be bound on the left-hand side Variable.
If you want to bound another data then you need to unbound that Variable first.
In Erlang Shell you can use f() function to unbound all the Variables. and to unbound any particular Variable use f(Variable_Name).
For Example:
> One = 2.
2
> f(One).
ok
> One = 1.
1
Now, Variable One is bounded with value 1.
That's it.

Modified On Mar-09-2016 11:20:08 PM

Don't want to miss updates? Please click the below button!

Follow MindStick