[erlang-questions] Re: Using match in guards

Dale Harvey dale@REDACTED
Tue Dec 22 00:34:53 CET 2009


you can use macros to clean up some of the checks, but you cant test for
something thats impossible with a guard test

-define(is_regex(A),
       (is_tuple(A) andalso (element(1, A) == regex))).

search(S) when ?is_regex(S) ->

2009/12/21 Zoltan Lajos Kis <kiszl@REDACTED>

> Sorry, sent it too early :) Wanted to ask for an example where this format
> cannot be used.
>
>
> Zoltan Lajos Kis wrote:
>
>> search({regex, _} = S) ->
>>  ...
>>
>> Zoltan.
>>
>> caio ariede wrote:
>>
>>> Just correcting my example:
>>>
>>> search(S) when S = {regex, _} ->
>>> ...
>>>
>>> Caio Ariede
>>> http://caioariede.com/
>>>
>>>
>>>
>>> On Mon, Dec 21, 2009 at 9:01 PM, caio ariede <caio.ariede@REDACTED>
>>> wrote:
>>>
>>>
>>>> In function guards we can use functions like is_string/1 and
>>>> is_number/1.
>>>>
>>>> But I'm needing to check a generic type defined by {type, Value} but
>>>> *in guards* like this:
>>>>
>>>> search(S) when N = {regex, _} ->
>>>> ...
>>>>
>>>> I know that I can do that with search(S = {regex, _}), but my example
>>>> was only for representing the problem.
>>>>
>>>> The main question is: there is a way for using match in guards? Or
>>>> something like this?
>>>>
>>>> Caio Ariede
>>>> http://caioariede.com/
>>>>
>>>>
>>>>
>>>
>>> ________________________________________________________________
>>> erlang-questions mailing list. See http://www.erlang.org/faq.html
>>> erlang-questions (at) erlang.org
>>>
>>>
>>>
>>
>>
>> ________________________________________________________________
>> erlang-questions mailing list. See http://www.erlang.org/faq.html
>> erlang-questions (at) erlang.org
>>
>>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>


More information about the erlang-questions mailing list