[erlang-questions] Wildcard matching a list of strings vs atoms/binaries

Ivan Carmenates García co7eb@REDACTED
Wed Apr 17 22:51:14 CEST 2013

Greetings Olav,


I don’t understand why you try to math using that kind pattern, you can use
the common way.


Instead of using ([0,1,2] ++ _) = [0,1,2,3,4] you can use  [0,1,2| _] =
[0,1,2,3,4] pattern matching.













De: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] En nombre de Olav Frengstad
Enviado el: miércoles, 17 de abril de 2013 16:27
Para: erlang-questions@REDACTED Questions
Asunto: [erlang-questions] Wildcard matching a list of strings vs




I'm getting some unexpected behavior when trying to pattern match the head
of a list.


When matching against a list of integers I can successfully do a wildcard

27> ("ab ++ _)  = "abcd".


But when trying to do the same with a list of atoms i get the error: * 1:
illegal pattern:

28>  ([a,b,c] ++ _) = [a,b,c,d].

* 1: illegal pattern


So just making sure there's no magic in string matching i also try with an
actual list of integers:

29> ([0,1,2] ++ _) = [0,1,2,3,4].  



Why can't I pattern match a lists with other values integers?


What i'm looking to achieve is to provide wildcard matching on a gen_event
handler so I can do matches like this:


handle_event((Match ++ _), State#state{match = Match}) ->

% handle


Any other alternatives is appreciated, current implementation uses


Med Vennlig Hilsen

Olav Frengstad


Systemutvikler // FWT

+47 920 42 090

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130417/0fa623e7/attachment.htm>

More information about the erlang-questions mailing list