[erlang-questions] The Beauty of Erlang Syntax
Kostis Sagonas
kostis@REDACTED
Thu Feb 26 23:27:55 CET 2009
Zvi wrote:
> Joe,
> I've read your book. You didn't get my point.
> I can enter into irb shell (out of the box) and enter this one liner:
>
> irb(main):002:0> (1..10).each { |i| puts "i=#{i}" }
> i=1
> i=2
> i=3
> i=4
> i=5
> i=6
> i=7
> i=8
> i=9
> i=10
> => 1..10
>
> To do the same in Erlang shell (out of the box) with your for/3 :
>
> 1> For0 = fun(Max,Max,F,_) -> F(Max);
> 1> (I,Max,F,Self) -> F(I), Self(I+1,Max,F,Self)
> 1> end.
> #Fun<erl_eval.4.105156089>
> 2> For = fun(Min,Max,F) -> For0(Min,Max,F,For0) end.
> #Fun<erl_eval.18.105910772>
> 3> For(1,10,fun(I)-> io:format("i=~b~n",[I]) end).
What prevents you from writing the following one liners?
1> [io:format("i=~b~n",[I]) || I <- lists:seq(1,10)].
or
2> lists:foreach(fun (I) -> io:format("i=~b~n",[I]) end,
lists:seq(1,10)).
Kostis
More information about the erlang-questions
mailing list