[erlang-questions] questions about ERLANG!

Kid Erlang kiderlang@REDACTED
Sat Mar 28 10:39:23 CET 2009


hi everybody.  I have just discovered Erlang!  it is very exciting.  I have
been making scripts with perl that call each other so I have hundreds of
scripts running at once.  my friend told me Erlang has processes so I
thought I could replace my scripts with Erlang!  I had bought the book
programming Erlang.  very good book and fun to read, but I still have
questions about Erlang!  it is my first functinal language and so far that
has been pretty confusing!  I am still reading the book too.

recursive blew my mind!  I have tried forever on this code and I finally
have it working.  there are no for loops in erlang so I had to write my own
into recursive.  here is the program what I came up with:

-module(adder).
-compile(export_all).

add_up_list(List)->LengthOfList=erlang:length(List)-1,for_loop(0,LengthOfList,List).
for_loop(CurrentLocationInList,LengthOfList,List)->if
CurrentLocationInList==LengthOfList
true->0;false->lists:nth(CurrentLocationInList+1,List)+for_loop(CurrentLocationInList+1,LengthOfList,List).

the goal of this program is to take all the numbers of the list and add them
together.  but it will not compile!  here is the error:

~$ erlc adder.erl
./adder.erl:5: syntax error before: true
./adder.erl:4: function for_loop/3 undefined

where is my program wrong?  I have written programs before this and they
compiled.  but this one really stumps me.  I cannot figure out what is
wrong.

I have not got to the paralell part of Erlang yet but I hear it lets you
automagically scale into the cloud!  that is my goal with Erlang!

- Kid Erlang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090328/4f70c1c4/attachment.htm>


More information about the erlang-questions mailing list