[erlang-questions] Simple Erlang Recommendation (last returned value)

James Hague <>
Sat Jul 26 18:25:23 CEST 2008


On Fri, Jul 25, 2008 at 2:36 PM, Berlin Brown <> wrote:
>
> Yea, but that tends to work against the immutability feature of
> erlang?

Not at all.  Within a function, single-assignment is just a way of
associating a symbolic name with a variable.  No data being modified
at all when you say:

X = tl(L)

Code like this following is fairly common in Erlang:

X = tl(L),
X2 = tl(X),
X3 = tl(X2)

Again, no data is being changed.  They're just symbols representing
values.  And there no reason you couldn't say "I would like to use a
fresh symbol with the same name as a previous symbol," like this:

X = tl(L),
*X = tl(X),
*X = tl(X)

It's exactly the same thing as the previous example.  Previous values
of X are not modified.  In fact it would be easy to mechanically
preprocess Erlang code to have the *X names automatically turned into
distinct names.

James



More information about the erlang-questions mailing list