[erlang-questions] Illegal Guard?
Thu Feb 11 19:02:51 CET 2016
Why do you think "f(X, Y) when U = X+Y, U > 0 ; V = Y*X, V < 0 ->" is
I do think that this is ugly, and diminishes the boundary between function
body and function header, and leads to cluttered programs.
But in a logical sense, in the same way input arguments are allocated
private stack space (it is really heap at the OS level), even guards can
create variables in the private stack; and apply logical conditions on them.
*I am not advocating this as a good thing to do, but thinking out loud*
On Sun, Feb 7, 2016 at 7:49 AM, <> wrote:
> > 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions