[erlang-questions] Pattern-matching function?

Richard O'Keefe ok@REDACTED
Thu Oct 30 05:18:43 CET 2008

On 30 Oct 2008, at 3:00 am, Francois De Serres wrote:

> Hi there.
> I need a function that actually does pattern matching: pm(Tuple,  
> Pattern)->MatchedPattern|error

Patterns are not expressions, you cannot pass them as parameters.
What you CAN do is pass functions.

>> pm({a,b,c}, {a,X,Y}).
> {a,b,c}
>> X.
> b

You are trying to pass a variable into another function and
have it bound there.  That cannot happen.  Variables are not
values either, and cannot be passed as arguments.

There are also 'match specifications' which are data structures
that get processed sort of as if they were kind of not entirely
unlike patterns.

Could you explain what problem you are trying to solve
by doing this?  There is probably a simpler way.

More information about the erlang-questions mailing list