[erlang-questions] new new in parameterized modules causes beam_dead

Mikael Karlsson karlsson.rm@REDACTED
Sat Mar 13 18:47:17 CET 2010


2010/3/13 Richard Carlsson wrote:

> Mikael Karlsson wrote:
> ...
>
>> I like that the new function return the module like a tuple, it makes it
>> almost lika a dual nature of records and it makes it very easy to write
>> setter functions in the module:
>> -module(test,[A,B,C,D,E,F,G,H,I,J]).
>> -record(test,{a,b,c,d,e,f,g,h,i,j}).  %% record specification local in
>> module (no includes)
>> -export([set/2]).
>>
>> set(a,V) -> setelement(2,THIS,V);
>> %% or
>> set(b,V) -> THIS#test{b=V};
>> etc...
>>
>> Is this tuple format something that can be considered future proof in the
>> implementation of parameterized modules?
>>
>
> Definitely not. If/when these are made an official feature, they will
> be made a first-class opaque data type; this is exactly analogous to
> how funs were introduced in Erlang.
>
>    /Richard
>
>
OK,
thanks, should have known better...
Anyway if becoming official I think it would be good to be able to set
separate attributes in a simple way (like you can with records), especially
if you have many of them.

Until then:
I noticed that you can use both new or instance when setting attributes
set(a,X) -> new(X,B);
set(b,X) -> instance(A,X).

Is there a preferred way?

/Mikael Karlsson (now down-posting)


More information about the erlang-questions mailing list