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

Joseph Wayne Norton norton@REDACTED
Thu Oct 2 09:26:55 CEST 2008


Richard -

Thanks for your feedback/comments.  I will keep the patch as an internal  
patch until R11B is no longer in use and after mechanically replacing :new  
with :instance.

As an aside, what is the motivation for having both :new and :instance  
support?  In hindsight, I would have just stuck with using :instance if I  
had known about it in the first place :).

thanks,

- Joe N.

On Wed, 01 Oct 2008 19:26:42 +0900, Richard Carlsson <richardc@REDACTED>  
wrote:

> 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



-- 
norton@REDACTED



More information about the erlang-patches mailing list