[erlang-questions] hot-code replacement

jces@REDACTED jces@REDACTED
Tue Oct 17 05:22:10 CEST 2006


Cont'd: after 

>(lerl@REDACTED)3> Pid!not_finished.
>not_finished

you can edit start/1's "not_finished" section to a) io:write and b)
increment Arg by different amount.

start(Arg) ->
    receive
	finished ->
	    io:write(Arg);
	not_finished ->	   
	    io:write(Arg),
	    ?MODULE:start(Arg+42)
end.

then re-compile it in the running erlang shell.

Send the same old Pid, not a new one, a "not_finished" message and it will
a) increment Arg by 1 because the new version is not in place just yet,
and b) load the new version.

Send it another "not_finished" message and this time a) you will see the
new io:write happen, and b) Art is incremented by 42.

Finally, send it "finished" to see a final value, like 45.







More information about the erlang-questions mailing list