• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: associative lists [was Re: Choose from list]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: associative lists [was Re: Choose from list]


  • Subject: Re: associative lists [was Re: Choose from list]
  • From: "Mark J. Reed" <email@hidden>
  • Date: Thu, 21 Jul 2005 09:25:20 -0400

The difference between an associative array and a record is the nature of the keys.  A record has a fixed set of fields that are determined by the programmer and cannot be changed once the program is running.  An associative array has a dynamic set of fields that can grow and shrink at runtime. 

The field identifiers in a record are like variable names; the keys in an associative array can be any arbitrary value, though they're usually strings.

In a sense, records are a more limited type of associative array, and in many of the more dynamic programming languages, records are implemented using associative arrays.


On 7/21/05, has <email@hidden> wrote:
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. email@hidden>
 _______________________________________________
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

  • Follow-Ups:
    • Re: associative lists [was Re: Choose from list]
      • From: Emmanuel <email@hidden>
  • Prev by Date: Re: crop left half of image via script / iMagine Photo
  • Next by Date: Re: crop left half of image via script / iMagine Photo
  • Previous by thread: Re: associative lists [was Re: Choose from list]
  • Next by thread: Re: associative lists [was Re: Choose from list]
  • Index(es):
    • Date
    • Thread