Polymorphic record question

Andrew Lentvorski bsder@REDACTED
Mon Jun 19 11:39:06 CEST 2006


Christian S wrote:
> How about an accessor function:
> 
> sequenceNumber(#p2psyn{sequenceNumber=Seq}) ->
>  Seq;
>  ...
> sequenceNumber(#p2pfin{sequenceNumber=Seq}) ->
>  Seq.

*smacks forehead with palm for being an idiot*

Right.  I'm in a pattern matching language.  I should use a pattern 
match.  What a concept. ;}

Talk about missing the obvious.

> Or is the different kinds of packets not restricted, instead new ones 
> will be
> defined later on by dynamicly loaded code?

No, I'm not loading dynamically.  Your solution works great.

> Another idea could be to consider sequenceNumber to be part of the
> header and the data part of the payload, so you define
> -record(p2ppacket, {something, sequenceNumber, payload}).
> 
> and then various records that you put in the payload field. The downside 
> is that
> (Packet#p2ppacket.payload)#p2psyn.synData is a bit ugly to write.

Yeah, that's getting a little convoluted.  At that point, putting things 
into tuples and just recording the position starts to look more readable.

-a



More information about the erlang-questions mailing list