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

Anthony Ramine <>
Fri Jun 21 10:21:12 CEST 2013


Hello Richard,

What we currently have:

qual -> pat '<-' expr.
qual -> bin_pat '<=' expr.
qual -> expr.

I would keep it as is but compile every filter as an expression and the following grammar rule:

expr -> 'when' guard 'end'.

And then I would also add two generators which do not skip elements but crash instead:

qual -> pat '<:-' expr.
qual -> bin_pat '<:=' expr.

I do like the different direction you took though. Allowing only guards mean matches can be handled differently, thus one could write X = foo() instead of begin X = foo(), true end.

Regards,

-- 
Anthony Ramine

Le 21 juin 2013 à 03:34, Richard A. O'Keefe a écrit :

> 
> On 21/06/2013, at 12:35 PM, Anthony Ramine wrote:
> 
>> Guard semantics are not mentioned in the documentation about comprehension filters though.
> 
> Fair enough.  And I'm not the least little bit happy about the fact
> that comprehension filters aren't guards.
> 
> I would have expected
> 	'[' <expr> '||' <stuff> ']'
> where
> 	<stuff> ::= <stuff> ',' <stuff>
> 	         |  <pattern> '<-' <expression>
> 	         |  <pattern> '=' <expression>
> 	         |  <possibly parenthesised guard>
> 
> We can tolerate a thing being one way (X < Y is only a guard, and if X or Y
> raises an exception, it just fails) or all the other way (guards and
> expressions are identical), but a mixture is bound to confuse.
> 




More information about the erlang-questions mailing list