Fellow stackoverflow-ers,
I am currently learning Erlang.
Could someone point me why do I get an illegal guard expression
with this guard?
add_new_prime(Idx, Primes, Ref) when length(Primes) =:= 0 ; math:sqrt(Idx) < hd(Primes) -> Ref ++ [Idx];
If I "un-optimise" it by doing only add_new_prime(Idx, Primes, Ref) when length(Primes) =:= 0 -> Ref ++ [Idx];
it works. I've seen multiple examples where there are more than one 'statement' per clause but can't see why mine is not working.
Thanks a lot!
Please see:
In you case,
math:sqrt(Idx)
is not a valid guard expression.Read the documentation here: http://www.erlang.org/doc/reference_manual/expressions.html#id81357