OR construction in erlang ?
Mark Scandariato
mscandar@REDACTED
Tue Apr 12 21:19:35 CEST 2005
Olivier wrote:
> Hi everyone
>
> Is there an equivalent to the PHP "or" construction ? I'd like to be
> able to throw errors when a match fails, i.e. :
>
> ok = test_function(Args) or throw(error_in_test_function).
>
> I know I can achieve the same with a catch and case syntax but nesting
> several tests gets ugly (or increases the number of functions in a module).
>
> Thanks :)
>
> --
> Olivier
>
I often use something like:
some_function(Arg) ->
check(Arg),
make_use_of(Arg).
check(foo) -> ok;
check(bar) -> ok;
check(E) -> throw({double_plus_ungood, E}).
You can even leave off the last clause, if you're happy with a function_clause error. (In
which case, it would be nice to use a name like "good_arg" instead of "check").
Mark.
More information about the erlang-questions
mailing list