[erlang-questions] comma vs andalso

Robert Virding rvirding@REDACTED
Thu Jul 9 01:10:59 CEST 2009


2009/7/8 Richard Carlsson <richardc@REDACTED>

> Thomas Lindgren wrote:
> > Not to mention the twin set of type tests, introduced, as far as I
> > know, to get rid of the lone double entendre of float/1 (as a test or
> > conversion not the most frequent of operations). And now, for our
> > convenience, the shorter form of these tests is being deprecated.
> > Sigh.
>
> Oh, and I forgot this beauty, which is a consequence of the
> doubleplusweird scope rules for the old type tests in guards:
>
>  1> if integer(42) -> ok; true -> no end.
>  ok
>  2> if integer(42) == true -> ok; true -> no end.
>  * 1: illegal guard expression
>
> because, you see, it is only at the absolute top of the guard test
> that the name 'integer(X)' can be used to refer to the type test.
> Shove it into one side of an '==', and it is no longer recognized.


It has nothing to do with scope rules really. In the original guards only
simple tests were allowed so there was no problem. It only became weird when
expressions were allowed.

Life was simpler in the old days! :-)

Robert


More information about the erlang-questions mailing list