问题缘起:参阅 Erlang Question 邮件列表上的讨论(
http://groups.google.com/group/erlang-questions/browse_thread/thread/fed4e293a015ce8)。以下回复于该邮件列表。由于用的英文还是比较粗浅,我就不费神去翻译了。
I think flat module namespaces is a defect of erlang design.
For example, I write a foo.erl, And it works well. But maybe in a late erlang version (eg. R13B) also write such module named foo.erl. Then, you can see my application goes wrong.
How to avoid things like this? Let's see the following ways:
1. Adjust module searching paths, and let user path (which contains my foo.erl)
take precedence over erlang stdlib/otp path. But, this way can't always work well. If some other stdlib/otp modules use system foo.erl (not my foo.erl), Things goes wrong.
2. Write erlang modules always named with a prefix (a fake namespace. For example, projectname_foo.erl or organization_projectname_foo.erl). This way really can solve the problem. But, It seems ugly.
Is there a way let's user still can call foo:func (not call foo.erl provied by stdlib/otp, but my projectname_foo.erl)? I have a suggestion:
Can erlang provide a 'module name alias'? That is, I can rename a module's name temporarily in a module? For example:
-module(a_module_that_call_my<wbr></wbr>_foo).
-alias(foo, organization_projectname_foo). %% alias
some_func_call_foo() ->
foo:func(). %% same as: organization_projectname_foo<wbr></wbr>:func()
Currently I can do this by using the 'define' keyword. For example:
-module(a_module_that_call_my<wbr></wbr>_foo).
-define(Foo, organization_projectname_foo). %% alias
some_func_call_foo() ->
?Foo:func().
It works well, but a bit ugly.
分享到:
相关推荐
高性能集群服务器Erlang解决方案
Erlang开发及应用
erlang入门电子书 erlang编程 Introducing Erlang,作者Simon.St.Laurent
erlang文献及资料汇总 入门资料: erlang中文手册(R11B 文档译文,最适合入门) erlang位运算与二进制解析 erlang二进制高效编程 erlang异常处理详解 开发经验: 面对软件错误构建可靠的分布式系统 编写分布式的 ...
erlang 安装包
Erlang及其应用Erlang及其应用Erlang及其应用
erlang25.0 windows版本
erlang otp25 win安装包
erlang22最新下载包 erlang22.1.tar.gz erlang22最新下载包 erlang22最新下载包
ErlangB和ErlangC计算工具(exe可执行文件+excel两个) ErlangB和ErlangC计算工具(exe可执行文件+excel两个)
erlang 中文基础教程erlang 中文基础教程
erlang的高性能集群服务器,erlang解决方案。 供大家学习使用
erlang安装包
Erlang并发编程,Erlang程序设计,Erlang中文手册。 学习erlang的好资料。 Erlang是一个结构化,动态类型编程语言,内建并行计算支持。最初是由爱立信专门为通信应用设计的,比如控制交换机或者变换协议等,因此...
Programming Erlang
rabbitmq,erlang安装包
本书由Erlang之父Joe Armstrong编写,是毋庸置疑的经典著作。书中兼顾了顺序编程、并发编程和分布式编程,重点介绍如何编写并发和分布式的Erlang程序以及如何在多核CPU上自动加速程序,并深入地讨论了开发Erlang应用...
erlang资源,非常值得下载,二郎学习
阶段,也就是学会在社团的帮助下,脱离指南,解决实际问题。 本书假设读者精通基本的Erlang和OTP框架。在本书中,会对一些难以理解Erlang/OTP特性进 行解释,另外,希望不熟悉Erlang/OTP基本知识的读者自行学习必要...
erlang 程序设计 源码 erlang 程序设计 源码 erlang 程序设计 源码erlang 程序设计 源码