[erlang-questions] Illegal Guard?

ok@REDACTED ok@REDACTED
Sun Feb 7 03:19:36 CET 2016


> Team - Any idea?

What it says: you may not use '=' in a guard.

Come to think of it,
> 60> is_integer(A = 5).
is pretty horrible no matter where it occurs; it's one of
the least likeable features of Erlang.

As far as I know the reason '=' isn't allowed in guards
is to avoid things like

 f(X, Y) when U = X+Y, U > 0 ; V = Y*X, V < 0 ->
    ... is it OK to use U here? or V?

That problem can surely be solved, just like 'case':
if a variable is bound in every alternative of a guard,
it's bound, otherwise it's visible but unusable.
But before something like that could be adopted,
'andalso' and 'orelse' and worse still 'and' and 'or'
were allowed into guards, and things would have got
even more tangled.






More information about the erlang-questions mailing list