[erlang-questions] is this a well written function
Richard A. O'Keefe
ok@REDACTED
Fri Feb 13 03:32:35 CET 2015
On 12/02/2015, at 8:03 pm, Roelof Wobben <r.wobben@REDACTED> wrote:
>
> Thanks for all the remarks. I changed it all but one remark about your code ;
>
> When I do N1 = N0 + 1 then I get a error because N1 is imutable and cannot be changed.
Here's the code I wrote, pasted from that message.
display_numbers_loop(N, N) -> % 3; C
ok; % 4; F
display_numbers_loop(N0, N) -> % 5;
N1 = N0 + 1, % 6; C,D
io:format("Number: ~p~n", [N1]), % 7; D
display_numbers_loop(N1, N). % 8;
At the point that N1 = N0 + 1 happens,
N1 DOES NOT YET HAVE A VALUE, so there is no possible question of trying to change it.
In fact the code as posted works flawlessly. (I have tested it.)
I strongly suspect that you ended up with something like
N0 = N0 + 1
^
which will indeed produce the error you describe.
More information about the erlang-questions
mailing list