[erlang-questions] What is wrong with this list?

Peter K Chan peter@REDACTED
Tue Sep 4 22:29:37 CEST 2007

I think it would be nice if the compiler can output why a match fails
(e.g. {number, 1} does not equal {atom, java}).


When I first started learning Erlang, I was being killed by all sorts of
badmatch error, mostly because I forgot that variables need to have
capitalized names. Now that I am slightly more experienced, I am not
confused anymore, but I am very sympathetic to people just starting the
language. After all, to diagnose this error, you must be comfortable
with both pattern matching and the fact that variables have to be
Capitalized (a simple fact, but one that does not come to mind easily
when you are starting to learn a language).




From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of Dustin
Sent: Tuesday, September 04, 2007 2:05 PM
To: Lone Wolf
Cc: erlang-questions@REDACTED
Subject: Re: [erlang-questions] What is wrong with this list?



On Sep 4, 2007, at 10:42 , Lone Wolf wrote:

I have been trying this statement:
2> [java | python] = [1, 2, 3, 4, 5, 6].
But I got the following error:
=ERROR REPORT==== 4-Sep-2007::17:45:07 ===
Error in process <0.33.0> with exit value:
How to read Erlang errors? they are really obfuscated.


            I wouldn't say they're obfuscated.  This is actually a quite
useful error.  It's showing you the value you were trying to pattern
match against and telling you your match failed.


            Regarding your statement, it's not clear what you expect it
to do.  If you capitalize java and python (i.e. make them variables
instead of atoms), then it'd leave you with the values 1 and [2,3,4,5,6]
for Java and Python respectively.  Otherwise, it's just going to tell
you that that list doesn't equal a two element list where the first
element is the atom ``java'' and the second is the atom ``python.''



Dustin Sallings


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070904/f150553b/attachment.htm>

More information about the erlang-questions mailing list