[erlang-questions] nested variable assignment : bug or the expected behaviour ?

Michael Turner <>
Tue Jun 26 05:04:28 CEST 2012


Nice question. I'd like to know the answer myself. My guess:
committing to first-lexical-use-of-matching for variable binding in
expressions reduces opportunities to optimize the expression, since it
implies an order of evaluation that might not be optimal. This can't
(quite) be the explanation though, since Erlang is so lisplike in its
approach to the question "What's an expression?"

-michael turner

On Tue, Jun 26, 2012 at 7:55 AM, James Churchman
<> wrote:
> Small syntax related thing
>
> If i have a function like :
>
> f()->[J=100,J].
>
> Or put in the shell:
> {J=200,J}.
>
> Or
>
> erlang:'+'(J=10,J).
>
> Or any other combination of where i try to set a variable nested
> inside somewhere else, it will say "variable 'J' is unbound" .. is
> this the expected behaviour ?
>
> ( if i do bind the value before tho it will it will fail with no match
> of right hand side value XX which is to be expected )
>
> I only ask as i want to type :
>
> [
> {1, N1=now() ,0 },
> {2, N2=now() ,N1 },
> {3, N3=now() ,N2 }
> ]
>
> I realise I could generate all the NXX now's before, or write a
> function to put each now result in the flowing tuple but its just for
> some simple test code and the behaviour was not as i wanted :-)
>
>
> James
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list