[erlang-questions] Pattern-matching function?

Francois De Serres fdeserres@REDACTED
Wed Oct 29 15:00:08 CET 2008


Hi there.

I need a function that actually does pattern matching: pm(Tuple, Pattern)->MatchedPattern|error
> pm({a,b,c}, {a,X,Y}).
{a,b,c}
>X.
b
> pm({a,b,c}, {b,X,Y}).
{error, badmatch}
> pm({a,b,c}, {a,X}).
{error, badmatch}
etc.

This trivial code works only with the empty tuple/pattern :
pm(T,P) ->
    P = T, P.
because pattern variables (X, Y) are unbound at function call.

I tried to find a hint in the libs with no avail.
If anyone has a lead, can you please put me on track?

Thanks,
--
Francois

-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail



More information about the erlang-questions mailing list