[erlang-questions] The Beauty of Erlang Syntax

Zvi exta7@REDACTED
Thu Feb 26 20:36:28 CET 2009


This is very real *practical* example of repeating multiple times measurement
from the shell.
You can't define your _times function from the shell and it's not in
standard library, the closest is lists:foreach/2 .

So one need to define Times fun from the shell using Y-combinator, before
doing time measurement?

The second also, very practical. It's hard to work from shell in recursive
language, when you can't define recursive fun from the shell.
You can't use macros from the shell either.
I'd like to define loop funs and spawn processes from the shell, but the
only way is to use uggly Y-combinator trick.

The practical solution for this is to add times/1 and loop/1 to the
user_defaults.erl or something like this (and make sure that every Erlang VM
installation have this file ...).

Zvi


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 ;-)



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




More information about the erlang-questions mailing list