[erlang-questions] Re: Using match in guards

caio ariede <>
Tue Dec 22 16:48:05 CET 2009

The values {regex, Value} are generated through a syntax
transformation, with a grammar parsing. So, it's not possible to get
something like {regex, Value, foo, bar}.

I just need to check if it's a tuple and the first value is an atom
named "regex". The element/1 do this.

Thanks for concern :)

Caio Ariede

On Tue, Dec 22, 2009 at 12:01 PM, Kostis Sagonas <> wrote:
> 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