Erlang中的元组模块是什么? [英] What is a tuple module in Erlang?
问题描述
http://www.erlang.org/news/35 提到这将被记录在案,但我可以在文档中找不到。
http://www.erlang.org/news/35 mentioned that this will be documented, but I can't find it in the documentation.
推荐答案
元组是一个包含两个元素的元组,一个模块的名称和一个额外的参数列表。例如:
A "tuple module" is a tuple with two elements, the name of a module and a list of extra arguments. For example:
{my_module, [foo, bar]}
在函数调用中,可以使用这样的元组而不是模块名称。在这种情况下,被调用的函数将在参数列表的末尾作为附加参数获取有问题的元组:
Such a tuple can be used instead of a module name in function calls. In this case, the function being called will get the tuple in question as an additional argument at the end of the argument list:
3> Module = {lists, [[foo]]}.
{lists,[[foo]]}
4> Module:append([bar]).
[bar|{lists,[[foo]]}]
到:
7> lists:append([bar], {lists, [[foo]]}).
[bar|{lists,[[foo]]}]
保存元组模块为了向后兼容,因为它们是从语言中删除的参数化模块的实施机制在R16。
Tuple modules are kept for backwards compatibility, as they were the implementation mechanism for parameterised modules, which were removed from the language in R16.
这篇关于Erlang中的元组模块是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!