[erlang-questions] Abstract patterns, structs and frames

Richard O'Keefe ok@REDACTED
Tue Feb 24 01:22:57 CET 2009


On 24 Feb 2009, at 12:31 am, Richard Andrews wrote:

>> Yes, it means that both Abstract Patterns and (Frames or Structs)
>> might be implemented.
>
> As best I can understand - after reading the papers by Richard  
> O'Keef and Joe Armstrong - structs and frames are trying to solve  
> pretty much the same problem and the main distinction appears to be  
> that structs are named/tagged while frames are defined only by their  
> content.

Actually, tags are _optional_ in the frames proposal.
<Tag{ K1=E1, ..., Kn=En }>
is allowed, and is equivalent to <{'' = Tag, K1=E1, ..., Kn=En }>

> I don't see a need for the tag (ie. struct) and I think it might be  
> a problem in some cases.

Having tried to convert some large chunks of Erlang from records
to frames, I can say that it really helps a lot having a place to
put the record name.  And when you have a function with two or
more frame arguments, it can help you keep track of which is which.

I'm not yet convinced that tags are _essential_, but they are
definitely too useful to forbid.

> What situations can people see where the struct tag is better than  
> say, tag=someTagAtom in a frame?

It ensures that everyone uses the _same_ name for the tag field
(namely ''), it ensures that the name is an atom ('' should be
forbidden as a field name), it provides a hook for pretty-printers &c,
it increases readability.

The frames proposal and the struct proposal are essentially the same
thing.  There are minor differences of syntax, and I've listed a lot
more BIFs that should be provided, but nobody should think that there
are two rival proposals, just two independent drafts of the same
proposal.

>




More information about the erlang-questions mailing list