on_load
According to:
http://www.erlang.org/doc/reference_manual/code_loading.html
We can run code once we load the document by using a directive called on_load:
-module(test2).
-on_load(run_it/0).
run_it() -> io:format("RAN IT!~n").
Notice that an export isn't necessary! So from the shell when I do this:
> c(test2).
I get:
RAN IT!
ok
Just a neat little trick.
No comments:
Post a Comment