I just got started with Erlang. I am trying if statement. I found out one particular behavior which I do not understand.
the following statement does work perfectly.
some_comp(Arg1) ->
if
(cal(Arg1)>50000)->'reached';
true -> 'invalid'
end.
cal(Arg2)->
%% some calculation.
However the following shows an error syntax near if:
some_comp(Arg1) ->
Val=cal(Arg1);
if
(Val>50000)->'reached';
true -> 'invalid'
end.
cal(Arg2)->
%% some calculation.
my question is why does the error occurs. without the if statement the part Val=cal(Arg1) does work well
Because expressions should be separated by
,
, not;
:;
is the separator forif
/case
/receive
and function clauses.