[erlang-questions] eep: multiple patterns

Andras Georgy Bekes <>
Tue May 27 15:45:56 CEST 2008

> I think there is a problem. I think I can express a pattern that's
> matching must involve backtracking:
> F(A1,A2...) when ({X,_}=A1 or {_,X}=A1) and ({X,_}=A2 ...
> So this proposal leads to a language that's too powerful :-(
I think this was a mistake.

"({X,_}=A1 or {_,X}=A1)" means:
- test {X,_}=A1 then if matches, bind X
- test {_,X}=A1 then if matches, bind X (if it is not already bound)
- return with true/false according to the results
- forget anything except for the variable bindings.

So there is no backtracking here.
It's time to re-read the other parts of your proposal.

> Then as we allow = as a boolean test in guards we can extend it to be
> a valid *test* in list/binary comprehensions as well. It the match
> succeeds the test succeeds and exports the any new variable bindings.
> Someone asked for this earlier and while just having it in lc/bc
> might be a bit off having it as a valid *guard* test means it becomes
> acceptable as lc/bc test. It also easy to implement. I have the this
> feature already in LFE.
On our way towards an embedded Prolog :-)
No backtracking (only becktracking to the last generator), no logic 
variables, but a very expressive sublanguage. If the ='s are allowed in 
guards this can't be problematic to implement.


More information about the erlang-questions mailing list