[erlang-questions] conditional expressions
Wed Nov 19 16:10:09 CET 2008
Can someone please explain the tail recursion problem with andalso? Thanks.
> -----Original Message-----
> From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-
> bounces@REDACTED] On Behalf Of Mikael Pettersson
> Sent: Wednesday, November 19, 2008 03:09
> To: Richard O'Keefe
> Cc: erlang-questions@REDACTED
> Subject: Re: [erlang-questions] conditional expressions
> 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.
> erlang-questions mailing list
More information about the erlang-questions