Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a tuple module in Erlang?

http://www.erlang.org/news/35 mentioned that this will be documented, but I can't find it in the documentation.

like image 291
rongtou Avatar asked Jun 06 '13 11:06

rongtou


People also ask

What is a tuple in Erlang?

Erlang - Tuples. A tuple is a compound data type with a fixed number of terms. Each term in the Tuple is called an element. The number of elements is said to be the size of the Tuple. An example of how the Tuple data type can be used is shown in the following program. Here we are defining a Tuple P which has 3 terms.

What is a tuple module?

A "tuple module" is a tuple with two elements, the name of a module and a list of extra arguments. For example: 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:

What is tuple data type in Python?

A tuple is a compound data type with a fixed number of terms. Each term in the Tuple is called an element. The number of elements is said to be the size of the Tuple. An example of how the Tuple data type can be used is shown in the following program. Here we are defining a Tuple P which has 3 terms.

Are tuple calls opt-in in Erlang (R21)?

With the latest release of Erlang (R21) tuple calls are opt-in. What that means is you have to use a compiler flag to make them usable. I also found discussions about removing it altogether. There is a lot of hate for this particular feature, and I haven’t found any good reason why.


1 Answers

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]]}]

This call is equivalent to:

7> lists:append([bar], {lists, [[foo]]}).
[bar|{lists,[[foo]]}]

Tuple modules are kept for backwards compatibility, as they were the implementation mechanism for parameterised modules, which were removed from the language in R16.

like image 84
legoscia Avatar answered Sep 25 '22 06:09

legoscia