MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

data structures

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22662] data structures
  • From: Maarten.vanderBurgt at icos.be
  • Date: Sat, 18 Mar 2000 01:27:40 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

Is there an elegant way of setting up data structures like you can do in
languages like C?
Something like the following example (what follows is a mixture between
mathematica code and C) explains what I am looking for:

Table[ person[i], {i,1,10}]

person[1].name = "Jeff"
person[1].length = 180
person[1].address.street = "Church Road"
person[1].address.city = "London"
person[1].favourite_colours[1]= "green"
person[1].favourite_colours[2]= "pruple"

person[2].name = "Jane"
person[2].length = 175
person[2].address.street = "Farm Road"
...

person[10]....

Then you can do things like:

Do[Print[ person[i].street ], {i,1,10}],

or

totallength = Apply[Plus, Table[ person[i].length, {i,1,10}]].



I know you could do something similar with nested lists.
But I do not want to remember that index 1 corresponds to 'name', index 2
corresponds to 'length' and that index 3,2 is 'city' and so on.


Any suggestions are welcome.
Thanks

Maarten van der Burgt
Leuven, Belgium








  • Prev by Date: Re: Real-time plotting
  • Next by Date: Re: running a program in batch
  • Previous by thread: Re: Image window via Mathlink
  • Next by thread: Re: data structures