[erlang-questions] what is the correct syntax to spawm a MFA with no arguments?

Richard Carlsson richardc@REDACTED
Thu May 1 18:39:05 CEST 2008


Jarrod Roberson wrote:
> so are you saying you can do hot code reloading _without_ using the MFA 
> version of spawn?

Yes. If you spawn a process whose starting point is in the same module,
you just use spawn(fun loop/0) or spawn(fun () -> loop(...) end). If you
spawn a process that starts in _another_ module, you can write
spawn(fun moo:loop()) or spawn(fun () -> moo:loop(...) end). Of course,
in the latter case the function must be exported from moo, but you never
need to export a function in the current module just because you want it
to be the starting point of a process.

I know that Joe's book (sadly) contains a remark that indicates that
there is some problem with dynamic code loading and spawning from a fun,
but that remark is just misleading.

If you avoid exporting functions that shouldn't really be exported,
tools like dialyzer can make a much better job of finding out what
your program is doing (and tell you where you screw up).

     /Richard



More information about the erlang-questions mailing list