[erlang-questions] Guards syntax for multiple values
Tue Mar 26 16:50:42 CET 2019
On 26.03.19 09:08, Loïc Hoguin wrote:
> What about compiler trickery, as mentioned earlier in the thread? Either
> allowing 'lists:member(Var, <list literal>)' or 'Var in <list literal>'
What do you think about using <bound Var> <- <list literal> instead
of introducing a new 'in' operator which might cause clashes with
existing code? Okay, in list comprehensions this is not exactly a
boolean expression, and a bound var would be shadowed there, but at
least that's an existing operator that semantically comes closest
somehow (it even looks a little bit like the algebraic 'is element of'
operator). The advantage of using a operator is IMO that it is less
surprising, if there are restrictions like "only apply this to literal
lists", as '++' in pattern has also certain restrictions on the LHS.
Is the "<list literal>" restriction a little bit too strong? Wouldn't
"<list with a fixed number of elements>" be sufficient?
> and rewriting this at compile time as a more verbose series of =:= tests
> and/or separate clauses? This would fit a lot of use cases.
More information about the erlang-questions