Erlang’s Dynamism
This is more verbose answer to @bubbafat twitt-question. It started lkie this:
- @bubbafat: Functions used by spawn to start a process must be exported. Why doesn’t erl compiler error when this is missed? #erlang
- @danielllo: @bubbafat ‘cos it is possible to define and load new modules later on during runtime in #erlang
- @bubbafat: @danielllo Thx. Do you mean redefining the module at runtime or that the func might resolve in a different module loaded later? #erlang
- @danielllo: You have many ways of referencing #erlang module:function not known at compile time.
-
- you can load the precompiled module at later time from a path not being provided to compiler.
- you can use M:F(Args) function invocation in #erlang, any of M, F, Args being variables dynamically referencing module, function and argument list.
- you can construct erlang AST tree programmaticaly, compile it at runtime and load the resulting beam.
- you can acheive the p.3 result using a helper tools such as LFE, Smerl or “Dynamic” module generation with compile-time macros
- … and I’m sure there is more