Which is fine.
Thanks,
Yurii.
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
I believe you mean parametrized modules, since they are basically a
tuples in runtime, where first element is module name. Those are two
different concepts.
In general I think that parametrized modules are here to stay, since
so many projects are using it, including OTP code itself (mnesia).
Although it would be nice if they are actually moved into "official"
part of language.
Best,
Gleb
> I believe you mean parametrized modules, since they are basically a
> tuples in runtime, where first element is module name. Those are two
> different concepts.
Well, this is a "hack" used to enable parametrized modules. I,
however, use it outside of parametrized modules (just make functions
accept the value tagged with the module name as the last argument).
This is why I prefer calling them tuple modules so that I don't run
into anti-parametrized modules crowd when it is uncalled for (the
general consensus on IRC is that as long as your module is not
parametrized but explicit, you're fine).
>
> In general I think that parametrized modules are here to stay, since
> so many projects are using it, including OTP code itself (mnesia).
> Although it would be nice if they are actually moved into "official"
> part of language.
Exactly. That's why I would love to hear from the OTP team.
Yurii.
Why do you need wrapping module name in a tuple? It works without it:
Eshell V5.9 (abort with ^G)
1> erlang:length([1,2,3]).
3
2> M = erlang.
erlang
3> M:length([1,2,3]).
3
Is there any case when wrapping is necessary, which I'm missing?
Best,
Gleb
That was just a minimal (and useless) case of how tuple modules
behave. This is a far bigger deal when you have records (or just
tagged tuples) and modules named according to them. One of the real
use cases is misultin_req:
https://github.com/ostinelli/misultin/blob/master/src/misultin_req.erl
Yurii.
AFAIK, yes
On Wed, Jan 18, 2012 at 18:40, Jon Watte <jwa...@gmail.com> wrote:AFAIK, yes
> Will "fun M:F/A" survive reloads and old code purge, and behave like the
> tuple function?
...or would we be required to replace the above with:
67> F=fun erlang:length/1.
#Fun<erlang.length.1>
68> F([1,2,3]).
3
Kind regards,
V/
Afaik this syntax is here to stay.
The syntax which lifetime is undefined yet is syntax mentioned by Yuri at the beginning of the conversation
Yes. This behavior is documented at the end of section 7.17 in
the reference manual:
http://www.erlang.org/doc/reference_manual/expressions.html#id77989
/Björn
--
Björn Gustavsson, Erlang/OTP, Ericsson AB
Yes. This will continue to work regardless of what
happens to parameterized modules. (This syntax
is much older than parameterized modules.)
/Björn
--
Björn Gustavsson, Erlang/OTP, Ericsson AB
No, we don't expect to keep them.
As pointed out by others, "tuple modules" is just an implementation
detail of parameterized modules (which is an experimental feature).
We have not reached a decision yet, but in the future we expect
we will do one of two things:
* Remove parameterized modules completely from the compiler
and run-time system.
OR
* Implement parameterized modules properly by creating a new
data type, both to allow better type checking by Dialyzer, and
to possibly improve performance.
/Björn
--
Björn Gustavsson, Erlang/OTP, Ericsson AB
Understandable. The only problem that I see with this decision is that
a considerable number of projects use this feature, even without using
parametrized modules directly (off the top of my head I can remember a
few but I am pretty sure there's much more).
And yes, I do understand that this feature was experimental. But
there's also reality of its use.
Yurii.
2012/1/23 Björn Gustavsson <bgust...@gmail.com>:
Is there any way tuple module calls can be separated from parametrized
modules and subsequently documented and become part of standard
Erlang?
Yurii
To inform our decision, it would be very interesting to know:
1) Why are projects using "tuple modules"? Is is because
the syntax is easy to use or is because of performance or
some other reason?
2) Could the projects use parameterized modules instead?
3) Which are the projects?
I can't speak for everybody, but I can speak of our own use. In
different cases it is obviously a slightly different reason. In our
latest case, it is not an "ease of use" of the syntax, but a whole way
to establish a certain type of operations. This project (not yet
released as open source, but eventually will be) is a relational
database mapper akin to ActiveRecord.
It allows us to map records describing the structute of tables to be
mapped to modules that implement their functionality.
So, suppose we have db_User record:
-record(db_User, { id, email, password }).
and a respective db_User module:
-module(db_User).
-extends(db_model).
-include("models.hrl")
As you can see, this module exports nothing. However, because of
-extends attribute, it will redirect all those missed calls to
db_model module. With tuple calls, the magic happens around there.
When, for example, someone executes User:save(), it gets ultimately
converted to db_model:save(#db_User{}) which can take care of saving
the record. Moreover, db_model:save/1 attempts to call before_save /
after_save callbacks if they are defined in db_User. The way it does
it is fairly simple: it just calls User:callback_name() and if it is
not defined, that call again goes to the default implementation in
db_model.
Of course it is technically possible to implement all of this without
tuple calls (at an expense of worse syntax), but obviously I'd rather
keep it as is as it works fantastically.
>
> 2) Could the projects use parameterized modules instead?
Some could, I suppose. But a lot of developers (including myself) are
avoiding them because of their many problems, like obscuring functions
arities. Tuple calls don't do that, your module source has functions
the way they eventually will be available in a compiled form.
I suppose you're talking about refined parametrized modules that don't
use tuples and use their own type. In this case the above project will
suffer a damage as it is an important feature of the project to keep
database records as records so that they can be easily matched. Unless
this new type provides a clear alternative to the above, it'll force
us into rewriting the whole thing once tuple calls are removed.
>
> 3) Which are the projects?
I just started collecting the list at
https://github.com/yrashk/9649-consequences — obviously this list is
far from completion and doesn't account for non-opensource projects.
Yurii.
Perhaps.
The problem with the current implementation of "tuple modules"
is that the M in apply(M, F, A) and M:F(...) has a strange type, i.e. M can
be either an atom or a tuple. Unless we implement parameterized modules,
we want M to be only an atom. (There is a run-time cost in the
implementation of apply/3 to allow parameterized modules/"tuple modules",
and parameterized modules prevented an optimization I wanted to do in the
compiler for R15B.)
We might consider an alternative implementation of "tuple modules"
that does not use apply(M, F, A) or M:F(...), using either new BIFs or new
syntax. (Example: tuple_module_apply(M, F, A) could behave as apply/3
currently behaves, or alternatively only allow M to be a tuple. This is not
a serious suggestion, just an example to make it clear what I mean.)
I suggest that you write an EEP.
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.
/Richard
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.
I wanted to follow up on this. I am investigating this whiole issue
(as I really would love to keep tuple calls) and I would like to know
whether you have any numbers on how significant the speed impediment
of this feature is (the run-time cost incurred in apply/3) that you
mentioned earlier? Do you have any comparisons?
Yurii