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

Hynek Vychodil vychodil.hynek@REDACTED
Sat Jul 26 19:29:09 CEST 2008


On Sat, Jul 26, 2008 at 6:25 PM, James Hague <james.hague@REDACTED> wrote:

> On Fri, Jul 25, 2008 at 2:36 PM, Berlin Brown <berlin.brown@REDACTED>
> 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)
>

Imagine this:

X = tl(L),
... many messy lines ...
*X = tl(X),
... another many lines ...
*X = tl(X),
... another many almost unreadable messy lines ...
sensitive_usage(X), % <--- buggy X value observed here

And my question is, where Value of X came from? It goes from L, but how long
it take and how many errors you can do when you will investigate?

It is reason why once variable assignment is in Erlang and why it is good
think. One advice for you: Don't change well proved language until you worth
know it.


> 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
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080726/99a16d36/attachment.htm>


More information about the erlang-questions mailing list