[erlang-questions] Intel Quad CPUs

Richard Carlsson richardc@REDACTED
Fri Sep 7 16:31:47 CEST 2007


David Terrell wrote:
> Interesting.  For those of us who like to bore everybody else with
> historical questions...  Was this the motivation for the change
> from integer(X) to is_integer(X) in guards?

No, that's a different story. When Erlang was a very new language,
the authors had the idea that guards were very different from
normal expressions (since the theoretical basis was stuff like
Guarded Horn Clauses). They chose to give guards a special scope,
so that you could write things like integer(X) and atom(X) and
that would be recognized as type tests. This was easy and compact.

The main drawbacks, which were mostly realized after a few years of
practical experience, were:

  - you couldn't just cut out a guard and paste it in somewhere,
    because the scope wasn't the same - atom(X) and the other tests
    were not defined outside guards

  - you couldn't access the type tests directly as a boolean value,
    as in "Bool = atom(A)" - you'd have to write "Bool = (if atom(A) ->
    true; true -> false end)", which is not exactly elegant

  - some names could have different meaning depending on whether they
    were used as guard tests or as normal expressions - float(X) is
    a boolean test for float-ness if it's a guard, but if it's a
    normal expression then it refers to the int-to-float conversion
    function

The is_... names were chosen both for clarity and to avoid the name
collision issue. They can be used everywhere.

     /Richard




More information about the erlang-questions mailing list