[erlang-questions] The Beauty of Erlang Syntax

Richard O'Keefe <>
Fri Feb 27 04:25:52 CET 2009


On 27 Feb 2009, at 7:48 am, Zvi wrote:
> Erlang:
> print_hi(10).
>
> print_hi(0) -> ok;
> print_hi(N) ->
>         io:format("hi~n"),
>         print_hi(N-1).

Stick
     for(L, U, F) when L =< U ->
	F(L),
	for(L+1, U, F);
     for(_, _, _) ->
	ok.
in your library.  (If it's OK for Ruby to have times in
a library, it's OK for Erlang.)  Now do

	... print_hi(1, 10, fun (I) -> io:format("hi~n") end) ...

and it's a one-liner.  Now that I have a for: module with
an integer range for/3 and a list element for/2, it really is
a one-liner for me.  Erlang makes it easy to hide the hard
parts!




More information about the erlang-questions mailing list