[erlang-questions] Funs

Bengt Kleberg bengt.kleberg@REDACTED
Mon Nov 26 09:18:09 CET 2012


Greetings,

Here are two reasons to use anonymous functions.

1) You do not want to create a real function.
2) You want to capture some variables into a function. Erlang shell ex:
Variable = 42.
Add_variable = fun (N) -> N + Variable end.
Add_variable( 2 ).


bengt

On Mon, 2012-11-26 at 10:09 +0200, Lucky Khoza wrote:
> Morning Erlang Developers,
> 
> I would like to ask about: when do we use funs or anonymous functions
> in Erlang?, I know what it is, but I can't really figure out when to
> use it and I saw an example of it being used with Mnesia
> transactions. 
> 
> May someone help in this regard please.
> 
> Kindest Regards
> Lucky Khoza
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list