Erlang Nested Records

Bengt Kleberg <>
Wed Mar 19 06:51:20 CET 2003


> Date: Wed, 19 Mar 2003 06:31:09 +0200
> From: "DANIESC SCHUTTE" <>
> To: "<"<>
> Subject: Erlang Nested Records
> Mime-Version: 1.0
> Content-Disposition: inline
> Content-Transfer-Encoding: 8bit
> X-MIME-Autoconverted: from quoted-printable to 8bit by 
hades.cslab.ericsson.net id h2J4biJ84408
> 
> Morning to everyone,
> 
> I have got a question about adressing nested records - is there a standard 
rule of thumb :) that can be used.
> 
...deleted
> how would one assign values to additional amounts internal records?

simplified records (shorter names) and example included below. please
let me know if i have unanswered your question, by changing record
names.


bengt

-module(record).
-export([main/1]).

-record( account, {
	 owner,
	 amount=0
	 }).

-record( bank, {
	 account0 = #account{},
	 account1 = #account{}
	 }).



main(_) ->
	io:format( "~n" ),
	Account0 = #account{owner=gustav},
	Account1 = #account{owner=kalle},
	Bank = #bank{account0 = Account0, account1 = Account1},
	io:format( "~w~n", [Bank] ),
	New_Bank = update(Bank, 0, 100),
	io:format( "~w~n", [New_Bank] ),
	init:stop( ).

update(Bank, Account, Amount) ->
    case Account of
	0 ->
	    Bank#bank{account0 =
			  (Bank#bank.account0)#account{amount = Amount}};
	1 ->
	    Bank#bank{account1 =
			  (Bank#bank.account1)#account{amount = Amount}}
    end.




More information about the erlang-questions mailing list