I am going through Erlang code.
tes_lib:check_operational(Config)
The above code is present in a module called Sample.erl
.
I am new to this language. My question is that I cannot see any include statement for the module tes_lib
in Sample.erl
. So, how come Sample.erl
is able to call the function check_operational
using tes_lib
module?
I thought that it should be like Java, where we first import the class and then call the function.
In Erlang, you don't need to "import" modules in order to be able to call them. A call like
tes_lib:check_operational(Config)
will be resolved at runtime. If thetes_lib
module hasn't been loaded yet, the code server will look for it in the load path, and if the module can't be found, the call will fail with anundef
error.There is an
-import
directive in Erlang, but it's usually considered bad style to use it. You could write:and then call
check_operational
as if it were a local function, without specifying the module name. Those function calls will be replaced by fully qualified calls at compile time.From the Erlang Programming Rules: