[erlang-questions] How to decide if the type of two variables isthe same record?

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Thu Jun 14 13:36:04 CEST 2007


I think it's reasonably safe to write code 
that does this:

same_record_type(A,B) ->
    is_tuple(A)
	andalso is_tuple(B)
	andalso size(A) == size(B)
	andalso element(1,A) == element(1,B).

That sums up the amount of testing that can
be done in order to verify that two variables
are of the same record type. These properties 
of records are also documented.

BR,
Ulf W

> -----Original Message-----
> From: erlang-questions-bounces@REDACTED 
> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of 
> attila.rajmund.nohl@REDACTED
> Sent: den 14 juni 2007 13:24
> To: erlang-questions@REDACTED
> Subject: [erlang-questions] How to decide if the type of two 
> variables isthe same record?
> 
> Hello!
> 
> Is there a simple way to decide that the type of two 
> variables is the same record? I could write something like this:
> case {Var1, Var2} of
>    {#rec1{}, #rec1{}} -> ok;
>    {#rec2{}, #rec2{}} -> ok;
>    _ -> not_ok
> end,
> 
> but is there something more elegant that doesn't have to 
> updated if a new record type can be expected?
> 
>  				Bye,NAR
> --
> "Beware of bugs in the above code; I have only proved it correct, not
>   tried it."
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 



More information about the erlang-questions mailing list