[erlang-questions] Simple Erlang Recommendation (last returned value)
YC
yinso.chen@REDACTED
Sun Jul 27 02:07:41 CEST 2008
On Sat, Jul 26, 2008 at 2:17 PM, James Hague <james.hague@REDACTED> wrote:
> > 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's just as bad when there's code like this:
>
> T2 = something(T),
> T3 = something(T2),
> T4 = something(T3),
> T5 = something(T4),
> T6 = something(T5)
>
> You may laugh at that code, but it's hardly uncommon, even in code
> written by experienced programmers. It's very easy to accidentally
> use T4 in a spot when you meant T3, or to have to renumber things and
> make a mistake.
>
> Please note that I am not arguing for changes in Erlang. I truly am
> not. But I can understand why this request comes up regularly.
>
>
There is a way to satisfy this request without breaking single assignment,
and that is to have a more sophisticated scoping.
For example, the above in lisp/scheme are:
(let ((t (something t)))
(let ((t (something t)))
(let ((t (something t)))
...)))
No mutabilities involved - just better scopes - can't be that bad for
Erlang, right? ;)
Cheers,
yc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080726/0eab5dd6/attachment.htm>
More information about the erlang-questions
mailing list