[erlang-questions] OTP-9649 and further changes
Wed Jan 25 16:14:46 CET 2012
On 01/25/2012 03:39 PM, José Valim wrote:
> Since the discussion steered towards "tuple modules", I am going to use
> the opportunity to ask.
> The fact that part of the standard library, like the dict module,
> receives the dict as last argument and the dict itself is a "tuple
> module" is an accident or a design decision? Does anyone actually write
> "Dict:find(Key)" instead of "dict:find(key, Dict)"?
This is just a coincidence. First, the dict module is much older than
the experimental implementation of parameterized modules. Second, the
data representation used by dict is explicitly documented to be
considered opaque and subject to possible changes. Nowhere is it said
that a dict is or will remain a callable object.
The reason it happens to work is that 1) the dict module uses a record
also called 'dict' for its hash table representation, and 2) when
performing a call to a parameterized module, the module object itself is
passed as an additional parameter, whose position (last) happens to
coincide with the expected position of the input dict in the API calls.
If the calling convention for parameterized modules would pass the
module object as the first argument (which it could do in a future
version of the compiler), or the dict module changed the record name
used for its tables, this would cease to work.
More information about the erlang-questions