开发者

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

I can't figure out how to import all the functions of a modul开发者_运维百科e without having to specify the individual functions.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜