[erlang-questions] The Beauty of Erlang Syntax

Hynek Vychodil vychodil.hynek@REDACTED
Thu Feb 26 20:11:28 CET 2009


Why not tailor your own function

times(F, N) when is_function(F,0), is_integer(N), N>=0 -> _times(F, N).

_times(_, 0) -> ok;
_times(F, N) -> F(), _times(F, N-1).

and than you can easily do times(fun()->io:format("hi~n"), 10).

But anyway, how often you need do something N times without take care for
result for *practical* purpose? I think you choose wrong example ;-)


On Thu, Feb 26, 2009 at 7:48 PM, Zvi <exta7@REDACTED> wrote:

>
>
>
> Tony Arcieri wrote:
> >
> > Reia also has ! (send) and receive which operate identically to Erlang,
> > but
> > in addition to that supports the obj.method syntax as syntactic sugar for
> > RPCs.  At the very least it's less ugly than Scala's !? operator for
> RPCs.
> >
>
> Tony,
> I disappointed, that you support regular Erlang processes in Reia.
> Functionality-wide you don't need it, since every Reia object is already
> process (off-course it's heavyweight gen_server process). Whoever want to
> write efficient code (may use assembler - i.e. Erlang :)
>
> All I say, that in high-level language you need gen_server like
> functionality on the language layer. In Erlang you end up writing
> boilerplate code for gen_servers. The current Erlang provide you with FS
> (Flexibility Syndrom). Even such a basic thing like a string: you can use
> list, you can use binary and some library functions even accept atoms
> instead of strings.
> Look for example at Ulf Wiger's plainfsm vs. gen_fsm . There is overlapping
> between plain Erlang and OTP. The good thing, that there is only one OTP
> (i.e. no competing high-level frameworks for Erlang).
>
> I want to concentrate on my problem domain and think in single paradigm.
> Instead erlang forces you to think in MFAs, funs, messages and gen_server
> primitives.
>
> Having both regular functions and funs is also FS (I understand that
> historically funs were introduced later, but still). I see regular function
> as constant fun.
>
> Regaring simple things in other languages - hard in Erlang. This was
> discussed many times and I'll not repeat it: interop, strings, collections,
> defining functions from shell, libraries with principle of maximum
> surprise,
> etc. I'll just give simple example like loop:
>
> Ruby:
> 10.times { puts "hi" }
>
> Basic:
> for i=1 to 10
>  print "hi"
> next
>
> Erlang:
> print_hi(10).
>
> print_hi(0) -> ok;
> print_hi(N) ->
>         io:format("hi~n"),
>         print_hi(N-1).
>
> or use LC, which is a little shorter, but build 2 unnecessary lists in
> memory:
>
> [ io:format("hi~n") || _<-lists:seq(1,10) ].
>
> or try to define factorial fun from shell:
>
> Fact = fun(0,_) -> 1;
>              (N,F) -> (N-1)*F(N,F)
>          end.
> Fact2 = fun(N) -> Fact(N, Fact) end.
>
> Uggggggly!
>
> Zvi
>
> --
> View this message in context:
> http://www.nabble.com/The-Beauty-of-Erlang-Syntax-tp22179816p22230905.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill your
boss.  Be a data hero!
Try Good Data now for free: www.gooddata.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090226/22dbfe94/attachment.htm>


More information about the erlang-questions mailing list