<p dir="ltr">Not so odd - look at the next line, at what you're telling it to print (it's not Current).</p>
<div class="gmail_quote">Den 12/02/2015 15.51 skrev "Roelof Wobben" <<a href="mailto:r.wobben@home.nl">r.wobben@home.nl</a>>:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks ,<br>
<br>
Stupid mistake I had to use rem.<br>
<br>
Now i have this :<br>
<br>
-module(side_effects).<br>
<br>
-export([display_numbers/1]).<br>
<br>
%%  display_numbers(N) displays the numbers from  1,2,...+N when N is a non-negative integer.<br>
%%  It is not defined for other arguments.<br>
%%  When N is a non-negative number, a helper function is called so it prints out<br>
%%  the numbers in the right order. This is a exercise from the Erlang Programming book<br>
%%  where I have to practice side-effects.<br>
display_numbers(Number) when is_integer(Number), Number > 0 -><br>
  display_numbers_loop(0, Number ).<br>
<br>
%%  When the control argument)(second argument) is equal to the number<br>
%%  the user has given, the end is reached and the last number is printed<br>
display_numbers_loop(Number, Number) -><br>
  ok;<br>
<br>
%%  When the contro argument(second argument) is not equal to the number<br>
%%  and the Current number is even,<br>
%%  The control argument is increased by one and the<br>
%%  display_numbers_loop function is called again with the new arguments.<br>
display_numbers_loop(Current, Number) when Current rem 2 == 0 -><br>
 io:format("Number:~p~n",[<u></u>Current + 1]),<br>
 display_numbers_loop(Current +1, Number );<br>
<br>
%%  When the contro argument(second argument) is not equal to the number<br>
%%  and the Current number is not even,<br>
%%  The control argument is increased by one and the<br>
%%  display_numbers_loop function is called again with the new arguments.<br>
display_numbers_loop(Current, Number) when Current rem 2 /= 0 -><br>
 display_numbers_loop(Current +1, Number ).<br>
<br>
but now I see only the odd numbers which I find wierd because  I say when Current rem 2 ==0 and that true for even numbers.<br>
So then the io can be found.<br>
<br>
Roelof<br>
<br>
<br>
<br>
Bengt Kleberg schreef op 12-2-2015 om 15:38:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Have you tested<br>
Current / 2 == 0<br>
with some values for Current?<br>
It is only true when Current is 0.<br>
<br>
The erlang shell is your friend for simple tests like this.<br>
<br>
<br>
bengt<br>
<br>
On 02/12/2015 03:33 PM, Roelof Wobben wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I have this code :<br>
<br>
-module(side_effects).<br>
<br>
-export([display_numbers/1]).<br>
<br>
%%  display_numbers(N) displays the numbers from  1,2,...+N when N is a non-negative integer.<br>
%%  It is not defined for other arguments.<br>
%%  When N is a non-negative number, a helper function is called so it prints out<br>
%%  the numbers in the right order. This is a exercise from the Erlang Programming book<br>
%%  where I have to practice side-effects.<br>
display_numbers(Number) when is_integer(Number), Number > 0 -><br>
  display_numbers_loop(0, Number ).<br>
<br>
%%  When the control argument)(second argument) is equal to the number<br>
%%  the user has given, the end is reached and the last number is printed<br>
display_numbers_loop(Number, Number) -><br>
  ok;<br>
<br>
%%  When the contro argument(second argument) is not equal to the number<br>
%%  and the Current number is even,<br>
%%  The control argument is increased by one and the<br>
%%  display_numbers_loop function is called again with the new arguments.<br>
display_numbers_loop(Current, Number) when Current / 2 == 0 -><br>
 io:format("Number:~p~n",[<u></u>Current + 1]),<br>
 display_numbers_loop(Current +1, Number );<br>
<br>
%%  When the contro argument(second argument) is not equal to the number<br>
%%  and the Current number is not even,<br>
%%  The control argument is increased by one and the<br>
%%  display_numbers_loop function is called again with the new arguments.<br>
display_numbers_loop(Current, Number) when Current / 2 /= 0 -><br>
 io:format("Number:~p~n",[<u></u>Current + 1]),<br>
 display_numbers_loop(Current +1, Number ).<br>
<br>
but when I do side_effects(10) I see all the numbers so I wonder why the when is not working ?<br>
<br>
Roelof<br>
<br>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
<br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
</blockquote></div>