yazz.com
yazz.com

Reputation: 58786

In Erlang how can I import all functions from a module?

I can't figure out how to import all the functions of a module without having to specify the individual functions.

Upvotes: 10

Views: 9338

Answers (3)

Roberto Aloi
Roberto Aloi

Reputation: 30985

Reading from the Erlang Programming Rules:

Don't use -import, using it makes the code harder to read since you cannot directly see in what module a function is defined. Use exref (Cross Reference Tool) to find module dependencies.

Upvotes: 7

archaelus
archaelus

Reputation: 7129

As Christian says, "It is not possible to import all functions from a module." The compiler has no import_all directive and I think this is done deliberately to discourage excessive function importing.

Importing functions instead of fully qualifying them M:F(...) is usually bad style. There is a semantic difference between calling a module-local function and a function in another module (code-loading rules), so I think it's best to make foreign calls explicit. One could possibly make exceptions for importing dict/lists/sets module functions, as those are commonly understood and are unlikely to change during a code upgrade.

Upvotes: 12

Christian
Christian

Reputation: 9486

It is not possible to import all functions from a module.

Upvotes: 7

Related Questions