[erlang-questions] The Beauty of Erlang Syntax

Zvi <>
Thu Feb 26 23:16:35 CET 2009


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).        
i=1
i=2
i=3
i=4
i=5
i=6
i=7
i=8
i=9
i=10
ok
4> 



Joe Armstrong-2 wrote:
> 
> for(Max,Max,F) ->  F(Max);
> for(I,N,F) -> F(I),for(I+1,Max,F).
> 
> for(1,10, fun(I) -> io:format("...." end)
> 
> The code is *shorter than the documentation"
> 
> writing the code is quicker than finding the documentation and reading it
> - this
> is true in most programming languages which is why programmers write
> code.
> 
> This happens all the time I wanted hex2int after 20 seconds in google I
> gave up
> and wrote it myself - this is also true for javascript C, ... as Wirth
> once said
> It is better to know one langauge very well that to know many languages
> incompletely..
> 
> Hint: read books and type in the examples. for/3 is in my book :-)
> don't rely on the web for information - (example Douglas Crockford's
> Good Parts of JavaScript - I learnt more in half an hour reading this
> than dozens of
> hours reading appallingly bad articles on the web)
> 
> 
> /Joe Armstrong
> 
> 
> On Thu, Feb 26, 2009 at 10:12 PM, Zvi <> wrote:
>>
>>
>>
>> Kevin Scaldeferri wrote:
>>>
>>> If you want to have only one way of doing anything, perhaps you should
>>> try Python.  I hear that's one of their design principles.
>>>
>>
>> Kevin,
>> I playing a devil advocate here (actualy some company paid me to be a
>> devil's advocate :)
>> I can adopt to any syntax and semantics. I already use Erlang and love
>> it. I
>> just think of it as a low-level language, kinda parallel and distributed
>> COBOL :) There are some simple things that hard to do in Erlang. That's
>> the
>> reason, why project like Disco uses combination of Erlang+Python and
>> Fuzed -
>> Erlang+Ruby.
>>
>>
>> Kevin Scaldeferri wrote:
>>>
>>> Anyway, the point is, if times() is something you do a lot, just write
>>> it and get on with your life.  If it matters to you a lot, make an
>>> argument for why it's generally important and submit a patch to the
>>> standard libraries.
>>>
>> Obviously you didn't read the list of things hard in Erlang, simple in
>> other
>> langs. Repeat N times, is just a simplest example. In Jim Larson's
>>
>> Times, just a case of "for" loop.
>> I working on generic collections library for Erlang, where will be
>> ranges.
>> Someting like:
>>
>> R = gc_range:new(1,10).
>> gc:foreach(fun(_)->io:format("hi~n") end, R).
>>
>> Zvi
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/The-Beauty-of-Erlang-Syntax-tp22179816p22233815.html
>> Sent from the Erlang Questions mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> 

-- 
View this message in context: http://www.nabble.com/The-Beauty-of-Erlang-Syntax-tp22179816p22234998.html
Sent from the Erlang Questions mailing list archive at Nabble.com.




More information about the erlang-questions mailing list