[erlang-questions] style question - best way to test multiple non-guard conditions sequentially

Anthony Ramine n.oxyde@REDACTED
Thu Jun 20 17:42:27 CEST 2013


Because changing it at this point would be weird. And because guards have special semantics and can't fail.

Supporting expressions now would mean weird semantics like in comprehensions, where you can't distinguish a guard from an expression and know that they are compiled differently, or breaking existing code such as "if length(X) =:= 3 -> ... ; ... end": if X is not a list and that expression is evaluated with guard semantics, the first clause is skipped, whereas if it is evaluated with expression semantics, the code crashes.

If I understood things correctly, Erlang is supposed to have a cond Clauses end expression —try to evaluate "cond" in Erlang, it's a syntax error because cond is a reserved keyword—, which is the same as if but with tests compiled with expression semantics. Maybe it should be implemented for real.

Regards,

-- 
Anthony Ramine

Le 20 juin 2013 à 17:29, Jonathan Leivent a écrit :

> OK - I will then add a word to the above question: why does Erlang *still* require the conditions in an if statement to be guards?
> 
> How hard is it to remove this restriction?




More information about the erlang-questions mailing list