[erlang-questions] pattern match test operator

Andras Georgy Bekes <>
Mon Nov 19 14:45:47 CET 2007


> > I can't see when I would want to do a match against 
> > a pattern containing only '_'s and if that is true I wouldn't need
> > to match again to retrieve some of the internal terms later on. In
> > this case, it's better to match even the internal structure from
> > the start.
What if you want to filter a list or query a database with two patterns?
You don't (yet) want to retreive the internal terms, just want to have 
the elements matching certain patterns.

Instead of writing

[ X || X <- ListOrQLCTable
	case X of
	   PATTERN1 ->
	      true;
	   PATTERN2 ->
	      true;
	   _ ->
	      false
	end]

You could write this (assume ~= the pattern-match-test operator):


[ X || X <- ListOrQLCTable,
	PATTERN1 ~= X orelse PATTERN2 ~= X]

Isn't it nicer?

	Georgy



More information about the erlang-questions mailing list