Executing boolean expressions on a list

Erik Stenman Erik.Stenman@REDACTED
Mon Mar 17 20:04:13 CET 2003


Chris Pressey wrote:
> Bjorn Gustavsson <bjorn@REDACTED> wrote:
[...]
> > I not just me. When asking people in the OTP group, nobody liked the
> > idea of not checking the right-hand side of 'andalso' and 'orelse'. The
> > change would not be consistent with how 'and' and 'or' work.
>
> I can see why the thought of "true andalso 5" succeeding without an error
> would be disturbing to the OTP team.
>
> However, evaluating both sides for type correctness means that 'andalso'
> isn't really very short-circuiting... i.e. the only semantic difference
> between 'and' and 'andalso' is when the operands have side-effects, right?

No, both sides are not evaluated for type correctness,
but if the rhs needs to be evaluated then the result is checked for type
correctness.

i.e.
   true orelse 5
is ok, but
   false orelse 5
is not ok.
This way orelse and andalso always returns a boolean,
the "problem" is that any call on the rhs will not be tail-recursive, since
the result needs to be checked.

/Erik



More information about the erlang-questions mailing list