Re: associative lists [was Re: Choose from list]
Re: associative lists [was Re: Choose from list]
- Subject: Re: associative lists [was Re: Choose from list]
- From: has <email@hidden>
- Date: Thu, 21 Jul 2005 11:50:16 +0100
Michelle Steiner wrote:
>is "associative array" the new term for "record" in applescript?
No. In a record, data is stored in properties and retrieved using references to those properties, e.g.:
set rec to {foo:1, bar:2, baz:3}
foo of rec --> 1
In an associative array (a.k.a. hash, map, lookup table, dictionary) data is stored and retrieved using other data as lookup keys, each key being associated with one value stored in the collection, e.g.:
#!/usr/bin/python
d = {'hello world':1, 37:2, True:3}
key = True
print d[key] # --> 3
See <http://en.wikipedia.org/wiki/Associative_array> for a more detailed description.
AppleScript doesn't provide a built-in associative array type (yes, this is lame), but you can roll your own (tedious), use a third-party implementation (e.g. <http://applemods.sourceforge.net/mods/Data/Types.php>), or lever something like Satimage's XMLLib.osax (with caveats). There are plenty of past posts on this subject if you want to search the list archives.
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden