Given a positive number N, my print_even() function prints out all the even numbers between 1 and N:
-module(my).
-compile(export_all).
print_even(N) when N>0 -> even_helper(1, N).
even_helper(Current, N) when Current =< N ->
io:format("(Current = ~w)~n", [Current]),
case Current rem 2 of
0 -> io:format("Number: ~p~n", [Current]);
_ -> do_nothing
end,
even_helper(Current+1, N);
even_helper(Current, N) when Current > N ->
ok.
Here's some sample output:
28> my:print_even(10).
(Current = 1)
(Current = 2)
Number: 2
(Current = 3)
(Current = 4)
Number: 4
(Current = 5)
(Current = 6)
Number: 6
(Current = 7)
(Current = 8)
Number: 8
(Current = 9)
(Current = 10)
Number: 10
ok
Below is the code I'm using for a conditional break:
-module(c_test).
-compile(export_all).
c_break(Bindings) ->
case int:get_bindings('Current', Bindings) of
{value, 3} -> true;
_ -> false
end.
I set a conditional break on the following line in print_even():
case Current rem 2 of
...which according to the Erlang debugger docs should be legal. But no matter what I do, I can't get my c_break() function to execute. I expected execution to halt at the breakpoint when Current is equal to 3, but the code runs to completion, and the breakpoint is skipped. I even tried:
c_break(Bindings) ->
case int:get_bindings('Current', Bindings) of
_ -> true;
end.
But execution still won't halt at the breakpoint.
Update: I can get execution to halt if I use the following function for my conditional break:
c_break(_) ->
true.
If I change that to:
c_break(X) ->
io:format("~w~n", [X]),
true.
...then once again execution won't halt.