[erlang-questions] How to get more than one clause from one record ?

Bengt Kleberg <>
Tue Apr 2 10:13:48 CEST 2013


Greetings,

Is your goal to assign/bind the value of more then one member in a
record on a single line of code? Then you can use the way you have in
your example:

#r{c1=C1, c2=C2} = R.

This is assuming that R is a #r{}. Otherwise you will get a bad match
exception.


You mention "clause" in your question. Is that because you want to have
an example with a function clause or a case clause?


bengt

On Tue, 2013-04-02 at 15:20 +0800, 饕餮 wrote:
> How to get more than one clause from one record ?
> 
> 
> I just know this one:
> -record(r,{c1 = 1,c2 = 2}).
> #r{c1 = FirstC, c2 = SecondC} = #r{c1 = 1,c2 = 2}.
> 
> 
> Then FirstC == 1, SecondC == 2.
> 
> 
> It doesn't looks so well.
> Because we assign the value from left to right.
> 
> 
> Is there any way to write a better-look code?
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list