I am new to Erlang. If I do this
H = fun(X) -> X*X.
Then it is fine. But if I move that function to a module, it says "Illegal Expression". For example this
H = misc_functions:square.
Please help.
Erlang function references require the keyword fun
and the arity. Suppose that square
takes a single parameter, the correct assignment is:
H = fun misc_function:square/1
You can also do something like that:
1> F = fun(X) -> misc_function:square(X) end.
#Fun<erl_eval.6.13229925>
2> F(4).
16
3>
Defining a function that calls inside your desired function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With