how to represent multi-structure chain relationships

Bengt Kleberg <>
Mon Aug 14 07:45:12 CEST 2006


On 2006-08-12 15:16, Only OpenSource wrote:
> Hello
> 
> What is the recommended approach to represent multi-structure chain
> relationships in erlang ?
> 
> eg.
> CertEnvelope --> CertChain --> Cert Attribute(s)
> 
> In C, one would use a pEnv->pChain->pAttrib and work with the fields.
> How does one do it in Erlang ?

one way of doing it would be records:

-record( cert_chain, {
	cert_attribute
}.
-record( cert_envelope, {
	cert_chain
}.

you can access the attribute like this:
attribute( #cert_envelope(cert_chain=Chain} ) -> attribute( Chain );
attribute( #cert_chain(cert_attribute=Attribute} -> Attribute.

and add it like this:
attribute_add( #cert_envelope{cert_chain=Chain}=Envelope, Attribute ) ->
	Envelope#cert_envelope{cert_chain=attribute_add( Chain, Attribute )};
attribute_add( #cert_chain{}=Chain, Attribute ) ->
	Chain#cert_chain(cert_attribute=Attribute}.


bengt
-- 
    EPO guidelines 1978: "If the contribution to the known art resides
    solely in a computer program then the subject matter is not
    patentable in whatever manner it may be presented in the claims."



More information about the erlang-questions mailing list