[erlang-questions] questions about ERLANG!

Serge Aleynikov saleyn@REDACTED
Sat Mar 28 13:14:31 CET 2009


Little addition to Hynek's advice - once you master the recursive 
solution, you can search through the lists module and find this helpful 
lists:sum/1 function:

1> lists:sum(lists:seq(1,10)).
55

Kid Erlang wrote:
> 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
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list