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

假如想象 提交于 2019-12-21 08:59:26

问题


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


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/2503768/in-erlang-how-can-i-import-all-functions-from-a-module

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!