[erlang-questions] conditional expressions
Mikael Pettersson
mikpe@REDACTED
Wed Nov 19 10:08:32 CET 2008
Richard O'Keefe writes:
>
> On 18 Nov 2008, at 4:38 pm, Serge Aleynikov wrote:
>
> > Your 'must' statement is not entirely accurate.
>
> Was there any doubt about what I meant?
> Let's try again:
> both 'andalso' and 'orelse' in Erlang have the
> following properties:
> the first operand must either return 'true' or 'false'
> or raise an exception;
> the second operand, if executed, must either return
> 'true' or 'false' or raise an exception;
> the Dialyzer will complain if either operand looks
> as if it will return something other than 'false' or 'true';
> and above all:
> you CANNOT use them to get the same effect as
> Lisp's (OR - -) and (AND - -) or Python's similar
> operators, which allow a normal result from the
> second operand to be anything at all.
>
> I have in fact complained about this, not because I particularly
> want non-Boolean results from these operators, but because the
> code that's inserted to check makes them non-tail-recursive.
Indeed, the failure of these operators to be properly
tail-recursive makes them utterly useless, and dangerous.
The HiPE compiler once had a performance bug in its
register allocator because some code used an 'andalso'
to control a tail-recursive computation. Needless to say
I've since placed a ban on andalso/orelse in the HiPE code
I maintain.
More information about the erlang-questions
mailing list