[erlang-questions] The Beauty of Erlang Syntax
Thu Feb 26 21:21:39 CET 2009
What I find I do if I want to use more complicated expressions in the shell
is to define a small module containing the functions I need at the moment
and then throw it away when done. Sometimes I even bung them somewhere in
the modules I am testing and delete them when done.
One thing to remember is that there is no support in the erlang VM for
interpreted code. All functions exist in compiled modules. So it is
impossible to mix interpreted and compiled functions and in many lisp
systems, there are no interpreted functions. There is an interpreter written
in Erlang, erl_eval, which is used by the shell but it has no special status
in the system.
2009/2/26 Zvi <exta7@REDACTED>
> This is very real *practical* example of repeating multiple times
> 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
> installation have this file ...).
> 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:
> Sent from the Erlang Questions mailing list archive at Nabble.com.
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions