Alex Rivera | Logout

How to define an function in the eshell (Erlang shell)?

Asked 2010-01-14T17:09:15.777
41

Is there any way to define an Erlang function from within the Erlang shell instead of from an erl file (aka a module)?

Edit
Report

1 Answer

46

Yes but it is painful. Below is a "lambda function declaration" (aka fun in Erlang terms).

1> F=fun(X) -> X+2 end.
%%⇒ #Fun <erl_eval.6.13229925>

Have a look at this post. You can even enter a module's worth of declaration if you ever needed. In other words, yes you can declare functions.

answered 2010-01-14T17:15:11.727

Your Answer