[erlang-questions] How do I elegantly check many conditions?

mats cronqvist <>
Wed Mar 25 14:40:01 CET 2009


Hynek Vychodil <> writes:

> On Tue, Mar 24, 2009 at 9:24 PM, mats cronqvist <> wrote:
>
>     Hynek Vychodil <> writes:
>    
>     > code
>     >
>     > ok = is_new_email1(Email).
>     >
>     > doesn't looks like same amount of code
>     >
>     > try is_new_email2(Email) catch throw:email_in_use -> email_in_use end.
>     >
>     > First one turns return value to exception, second one turns exception to
>     > return value. Second one seems more code, does not?
>    
>      but the exception generated in example 1 is a worthless 'badmatch'.
>
> I can flexible choose which worth-full 'badmatch'  will be generated just
> using {ok, Email} = {is_new_email1(Email), Email}.

  That's just a stupid hack.

  Anyway, I don't understand what you're getting so worked up
  about. Basically all OTP functions return {ok,Val}, and that's not
  likely to change anytime soon, regardless of how dumb or smart it
  is.

  mats



More information about the erlang-questions mailing list