[erlang-questions] (Non)Parametrized modules, inheritance, and R15B02 issues?

Erik Søe Sørensen eriksoe@REDACTED
Sun Oct 14 23:55:33 CEST 2012


Given that the underlying mechanism stays, and only the syntactical
conveniences are under threat: to what extent can the current pmod handling
be replaced by / emulated with a parse_transform?
If it's possible to do it that way, that might provide the best of two
worlds: the existence of the pmod feature without having the maintenance
burden in the compiler.
Den 12/10/2012 10.04 skrev "Gleb Peregud" <gleber.p@REDACTED>:

> On Thu, Oct 11, 2012 at 11:52 PM, Evan Miller <emmiller@REDACTED> wrote:
> > I designed BossDB around parameterized modules because pmods allow one
> > to develop with a familiar ORM pattern in Erlang. I wanted a
> > record-oriented API that was simple, succinct, and comprehensible.
> > With pmods I was able to succeed in these goals. For example, to
> > create a new record:
> >
> >   Person = person:new(id, "Joe", "Armstrong")
> >
> > To save it:
> >
> >    case Person:save() of
> >        {ok, SavedPerson} -> % do something ...
> >        {error, ValidationErrors} -> % do something else ...
> >    end
> >
> > To access an attribute:
> >
> >    Person:first_name().
> >    "Joe"
> >
> >    Person:last_name().
> >    "Armstrong"
>
> I believe that someone from OTP team mentioned that the parametrized
> modules are to be deleted, but tuple modules will stay. Essentially
> this will mean that instead of writing:
>
> -module(person, [FirstName, LastName]).
> -compile(export_all).
> first_name() ->
>   FirstName.
>
> You will have to write:
>
> -module(person).
> -record(person, {first_name, last_name}).
> -compile(export_all).
> new(FirstName, LastName) ->
>   #person{first_name = FirstName, last_name = LastName}.
> first_name(Person) ->
>   Perosn#person.first_name.
>
> but you will still be able to do:
>
>    Person = person:new("Joe", "Armstrong").
>    Person:first_name().
>    "Joe"
>    case Person:save() of
>        {ok, SavedPerson} -> % do something ...
>        {error, ValidationErrors} -> % do something else ...
>    end.
>
> So from point of view of readability there will be no change,
> althought the amount of code in the model module (person.erl) will
> slightly increase.
>
> Please correct me if I am wrong.
>
> Cheers,
> Gleb
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121014/6daef782/attachment.htm>


More information about the erlang-questions mailing list