OR construction in erlang ?

Olivier olivier.sambourg@REDACTED
Tue Apr 12 22:24:15 CEST 2005


Hi again

> Good day,
>
> olivier.sambourg> ok = test_function(Args) or 
> throw(error_in_test_function).
>
> ok = test_function(Args) orelse throw(error_in_test_function).
>
> Best Regards,
> Vladimir Sekissov


Sadly it doesn't seem to work, as "ok = test_function(Args)" either 
matches (and is evaluated to "ok") or raises a run-time error (and is 
not evaluated to "false").

> 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.

I guess I'll have to do that, but it is basically a case / catch syntax 
: how would you do it in this case:

...
true = lists:member(Key, List),
false = lists:member(Key2, List),
...

All I can imagine is :

case lists:member(Key, List) of
	false -> throw(error_in_test);
	_ -> case lists:member(Key2, List) of
		true	-> throw(error2_in_test);
		_	-> continue with nested code or nested function calls
		end
	end,

Please tell me I'm wrong :)
Thanks for the help !

--
Olivier




More information about the erlang-questions mailing list