[erlang-questions] Static Map ( Keys known at compile time )

Richard O'Keefe raoknz@REDACTED
Tue Apr 30 04:28:59 CEST 2019


The advantage over nested records is fourfold.
Clarity: the factoring of a "record" into a nest of tuples
is invisible in the source code.  Use Foo#R_F rather than
Foo#R_F#N_G.  Easier to read.
Maintainability: changing the factoring does not affect
the field names.  Only the record declaration changes.
Space: the nested groups do not have tags.  If you have
say a 10-slot record containing 10 5-slot records, you
need 82 words.  With nested groups, you save 10 words,
or about 12% of the space.
Time: with tag-less nested groups, copying time is less.

Of COURSE nested records are a good approach right now.
It could just be a bit better.




On Tue, 30 Apr 2019 at 07:32, Kostis Sagonas <kostis@REDACTED> wrote:

> On 4/29/19 12:31 PM, Richard O'Keefe wrote:
> > It's not clear to me why you would have a record with
> > 50 fields.
>
> Same here, of course.
>
> >  Imagine for a moment that Erlang's record
> > declaration syntax were generalised slightly:
> >
> > '-' 'record' '(' <name> ',' <group> ')' '.'
> > where
> >    <group> = '{' (<field> | <group>)+',' '}'
> >    <field> = <name> ['=' <default expr>]
> >
> > The generalisation here is allowing <group>s as well
> > as <field>s inside <group>s.  A nested group would be
> > a nested tuple with no element reserved for a tag.  So
> > -record(foo, {{a,b},{c,d}}).
> > means that a typical instance would look like
> > {foo,{A,B},{C,D}}.
> > The time to fetch a field would be proportional to the
> > number of groups it is in; the time to replace it would
> > be proportional to the sum of the sizes of the groups
> > it is.
> > Put nested fields into groups that are commonly read
> > or written together, and you trade a small increase
> > in read time for a large decrease in write time, with
> > automatic economisation in pattern matching, but needing
> > special attention from the compiler to fully economise
> > updates.
> >
> > That would be a nice extension of Erlang records, letting
> > you make performance tradeoffs just by adding and removing
> > curly braces with no change to code elsewhere.
>
> I see very little benefit, if any at all, compared to the (natural, IMO)
> alternative of using nested records for such use cases:
>
>   -record(foo, {#grp1{a,b},#grp2{c,d}}).
>
> which requires no language (or implementation) extension.
>
> What am I missing?
>
> Kostis
> _______________________________________________
> 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/20190430/c7b9ee55/attachment.htm>


More information about the erlang-questions mailing list