[erlang-questions] Advanced Erlang Subtleties

Joe Armstrong <>
Fri May 20 18:23:57 CEST 2011


On Fri, May 20, 2011 at 5:45 AM, Jeff Schultz <>wrote:

> On Thu, May 19, 2011 at 11:02:35PM +0200, Joe Armstrong wrote:
> > > I can see the equivalent evaluation of "250"<250 being a common
> mistake,
> > > and always being false is hardly useful.
>
> > A "<" B when A and B have different types means A is
> > "less complex" than B. Lists and more complex than integers
> > "250" is a list so "250"<250 is false.
>

Another thought I had about this was that in some languages
"10" < 20 might be true, and "20" < 10 or 20 < "10" might be false.

In Erlang a string (list) is always bigger (ie more complex) than an
integer.

A Javascript programmer might get confused here.

Erlang:

 "12" + 1   => (exception)
 "12" - 1    => (exception)
 "12" > 2    => true
 "12" > 15  => true

Javascript:

"12" + 1 => "121"
"12" - 1  => 11
"12" > 2 => true
"12" > 15 => false

Overloading plus to mean either plus or string concatenation is
horrible - and shouldn't "-" mean string subtraction (sometimes)

so "123" - 23 =>100 and "abc" - "a" => "bc" and "abc" - "c" => "ab"
:-)

I prefer the Erlang method - but then I'm probably somewhat biased here...

This (Javascript) horrible way of doing things caused me
hours of debugging - since my debugger wrote strings without
the quotes so I couldn't see the difference between "123" and 123
when printed.

Javascript also crashes late, and variables in closures
can be changed after binding them into the closures ... and the
concurrency model is ... (isn't) - but it's fun to muck around with
and do things in the browser.


> > Suppose I want to make a Key-Value database, where the Key can be
> anything,
> > including 250 and "250" to make any form of ordered tree we need a total
> > order over all the keys.
>
> Indeed.  If we can have only one built-in comparison, it needs to be
> total over all values.  It is a pity that Prolog's distinction between
> term comparison and number comparison wasn't carried over to Erlang :-(
>
>
>    Jeff Schultz
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110520/658bbf82/attachment.html>


More information about the erlang-questions mailing list