[erlang-questions] Guards on assignment (i.e. assertions)
Garrett Smith
g@REDACTED
Mon Mar 1 21:49:22 CET 2010
On Mon, Mar 1, 2010 at 2:34 PM, Vlad Dumitrescu <vladdu55@REDACTED> wrote:
> On Mon, Mar 1, 2010 at 21:13, Garrett Smith <g@REDACTED> wrote:
>>> What value should A be matched to if B =< C?
>> There's no value -- the assignment fails.
>
> Ah, okay. I thought you meant something else, should have read more carefully.
>
> I think it would help reading some code, but it might be tricky to get
> the the grammar right. Could we have even
> A = {B when B>C, D when is_list(D)}
> or only
> A = {B, D} when B>C, is_list(D)
> ?
The guard would be applied with the assignment operator as a check
before the pattern matching was applied. So, only the second form.
More information about the erlang-questions
mailing list