[erlang-questions] checking for unbound?

Edmond Begumisa ebegumisa@REDACTED
Sun Nov 21 11:30:29 CET 2010


 From your example, I think what you're looking for is pattern matching...

case mnesia:dirty_index_read(myTable, value, indexField) of
    [] -> do something;  % nothing was returned
    [E] -> do something with E;  % 1 item was returned
    [H|T] -> do something with H and T  % more than 1 item was returned
end.

- Edmond -


On Sun, 21 Nov 2010 01:18:03 +1100, Andy Kriger <andy.kriger@REDACTED>  
wrote:

> Is there a way to test if a variable is unbound?
>
> I thought I could do something clever like...
> [E|EL] = mnesia:dirty_index_read(myTable, value, indexField),
> if <E is unbound> -> do something; % nothing was returned
>   length(EL) > 0 -> do something; % more than 1 item was returned
>   <E matches pattern> -> do something; % a match was returned
>   true -> do something % whatever is left
> end
>
> But I don't see a way to make the first test.
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


More information about the erlang-questions mailing list