Executing boolean expressions on a list

Richard Carlsson <>
Mon Mar 17 11:24:21 CET 2003

On Sat, 15 Mar 2003, Pierpaolo BERNARDI wrote:

> > Yes. However, it currently kills the tail recursion. The evaluation of
> > 'andalso' checks that both arguments are booleans.
> Drat. I hadn't realized this.  I'll have to recheck my uses of andalso
> in this new light.
> Couldn't the spec of andalso and orelse be changed as to not
> guarantee that the result is boolean? in this case they could return
> their second argument with no checking. Correct code shouldn't
> be affected by this.

Well, this is what I also said when we implemented it, but the OTP
guys were not convinced, and preferred to have the check there. But
perhaps your complaints will be more influential. Björn, are you
reading this?  :-)

> > With a bit of type
> > analysis, the check for the recursive case could be removed, making the
> > function tail recursive. The compiler will probably soon be able to do
> > this, but right now the resulting code is not tail recursive.
> But even if, it will be able to do so only in the case of a self recursive
> function, I think?  Certainly not across modules?

As long as it can be seen that the function always returns a boolean,
self-recursive or indirectly does not matter. But generally not across


Richard Carlsson ()   (This space intentionally left blank.)
E-mail: 	WWW: http://user.it.uu.se/~richardc/
 "Having users is like optimization: the wise course is to delay it."
   -- Paul Graham

More information about the erlang-questions mailing list