[erlang-questions] Re: Using match in guards

Kostis Sagonas <>
Tue Dec 22 15:01:35 CET 2009


caio ariede wrote:
> Thanks for all replies, but I needed something *in guards*. (not S = {regex, _})
> 
> Is a very strict behavior, so just element(1, S) == regex _sugested by
> Dale Harvey_, did the trick.
> 
> search(S) when element(1, S) == regex -> ...

Well, glad that you are happy with this solution, I am not sure what you 
meant by "a very strict behavior".  Note that the above test is not 
semantically equivalent to what you initially told us you want to check, 
namely that S is a 2-tuple tagged with the atom 'regexp'.

For example, the following call passes the element test:

	search({regexp, foo, {gazonk, 42}, bar})

Kostis


More information about the erlang-questions mailing list