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

Mikael Karlsson <>
Sat Mar 13 19:49:44 CET 2010


2010/3/13 Richard Carlsson wrote;

> Mikael Karlsson wrote:
>
>> 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.
>>
>
> Well, if you want to use an abstract module as a thing with setters
> and getters (with each "set" operation creating a new instance), you
> can get a long way by making better interface functions. For example,
> you could have a single "set" function that takes a proplist.
>
>
Yes, maybe I can also internally have a record definition with an instance
bound to one attribute, making it reasonable easy (and efficient?)  to
update single values.
-module(test,[A]).
-record(test_internal,{a,b,c,d}).
-export(...).
new() -> instance(#test_internal{}).
get(a) -> A#test_internal.a;
..
set(a,V) -> new(A#test_internal{a=V});
..


>  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?
>>
>
> The "instance" function is more primitive, and is called by the
> autogenerated "new" function. See slide 6 of
>
>  http://www.erlang.se/euc/07/papers/1700Carlsson.pdf
>
> If you write your own "new", you should call "instance" from it.
> It interacts with the inheritance mechanism, so there is more to
> think about if you do this (passing on Base correctly).
>
> In general, you should probably not call "instance" directly from
> any other function except "new".
>
>    /Richard
>

/Mikael


More information about the erlang-questions mailing list