Do funs behave during a code change?
Yes and no. A fun is a reference to code; it is not the code itself. Thus a fun can only be evaluated if the code it refers to is actually loaded on the evaluating node. In some cases, we can be sure that execution will never return to a fun. In these cases the old code can be purged without problems. The following code causes no surprises: Parent = self(), F = fun() -> loop(Parent) end, spawn(F). On the other hand, a bound fun will not be replaced. In the following example, the old verson of F is executed even after a code change: -module(cc). -export([go/0, loop/1]). go() -> F = fun() -> 5 end, spawn(fun() -> loop(F) end). loop(F) -> timer:sleep(1000), F(), cc:loop(F). This type of problem can be solved in the code_change/2 function in the standard behaviours.