OR construction in erlang ?

Mark Scandariato mscandar@REDACTED
Tue Apr 12 22:07:48 CEST 2005


Note that:

ok = test(Arg).

exits with a badmatch if test(Arg) doesn't return ok. (This is often good enough.)

The logical operators (or, and, xor, not, orelse, andalso) will exit with badarg if their 
operands are other than the atoms 'true' or 'false'.

Thus,

ok = test(Arg) orelse foo().

will either exit with {badarg, ok}, since the value of ok = ok is ok, or it will exit with 
{badmatch, ...}

Mark.

Vladimir Sekissov wrote:
> 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
> 
> olivier.sambourg> Hi everyone
> olivier.sambourg> 
> olivier.sambourg> Is there an equivalent to the PHP "or" construction ? I'd like to be 
> olivier.sambourg> able to throw errors when a match fails, i.e. :
> olivier.sambourg> 
> olivier.sambourg> ok = test_function(Args) or throw(error_in_test_function).
> olivier.sambourg> 
> olivier.sambourg> I know I can achieve the same with a catch and case syntax but nesting 
> olivier.sambourg> several tests gets ugly (or increases the number of functions in a 
> olivier.sambourg> module).
> olivier.sambourg> 
> olivier.sambourg> Thanks :)
> olivier.sambourg> 
> olivier.sambourg> --
> olivier.sambourg> Olivier
> olivier.sambourg> 
> olivier.sambourg> 
> 



More information about the erlang-questions mailing list