Erlang syntax error unclear

108 views Asked by At

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

1

There are 1 answers

2
Alexey Romanov On BEST ANSWER

Because expressions should be separated by ,, not ;:

Val=cal(Arg1),
if ...

; is the separator for if/case/receive and function clauses.