[erlang-patches] R12B-? compiler patch for parameterized modules

Richard Carlsson <>
Wed Oct 1 12:26:42 CEST 2008


Joseph Wayne Norton wrote:
> 
> The undocumented behavior of parameterized modules has changed since
> R11B.  A minor change to the compiler would permit usage of ":new" only
> if there does not exist a function having the same name and same arity. 
> The current behavior checks for only the same name.  Please consider
> this change to be included in a future release.

The idea is that if the user has already specified one or more functions
called new/_, it means he has taken the responsibility for that part of
the interface, and should call 'instance/N' himself, from at least one
of these new-functions. This makes it possible to have a set of exported
new-functions that do not include new/N. With your patch, the compiler
would always insert new/N if you omit it, unless you also add some
new compiler flag to suppress this - and I find that a worse solution.

A concrete example: with the current behaviour, you can have a module
such as:

  -module(m,[Ref,X,Y]).

  -export([new/1, new/2, get/0]).

  new(X) -> new(X, 0).

  new(X, Y) -> instance(make_ref(),X,Y).

  get() -> {X, Y, Ref}.

where 1) the module is actually abstracted over an extra variable that
you don't see in the interface functions (there is no new/3), and 2) the
order of the parameters to the new-functions is different from that of
instance/N (though I can't think of an example of when that would be
useful).

    /Richard



More information about the erlang-patches mailing list