How to remove allocated value of a specific variable in Erlang?

Total Post:128


 1159  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.
> 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.
  1. Re: How to remove allocated value of a specific variable in Erlang?

    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.
    > f(One).
    > One = 1.
    Now, Variable One is bounded with value 1.
    That's it.

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


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.