I have often seen people spawning new functions with arity 0 (no arguments) as:
spawn_link(fun function_name/0).
where function_name/0 can be for example:
function_name() ->
io:format("hello~n", [])
end.
Can I spawn in a similar way a function which takes a parameter? For example:
function_name(Arg) ->
io:format("hello ~p ~n", [Arg])
end.
Should I use
spawn_link(Module, Function, Arg)
or something else?
You can use that
spawn_linkwith arguments, build a lambda function (fun) with the specified arguments or just with fixed ones. So for example you could use, as you say, just:or export your own
spawn_link(orstart) in your module:or use a
fun:or if you internally call some function with fixed parameters:
where
Xin this case is the arity of themyfunfunction in each case.