• 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
key,value pairs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

key,value pairs


  • Subject: key,value pairs
  • From: "Steven D. Majewski" <email@hidden>
  • Date: Wed, 18 Jun 2003 15:03:52 -0400

It seems that, unlike Perl hashes or Python dictionaries, Applescript records
can only be accessed by a literal, not by a string -- is this correct ?

I need to set up several mappings of keys to values which may be read in from
a file ( or possibly gotten from a query to another application. )
They keys will be the same for all sets, but the values will be different.
( But all of the keys can be changed by editing the file, so the key names can't be
hardwired. ) Users will choose a set of values by project name.

Since I couldn't figure out how to do this with records, I tried creating a script
object to map names and values. However, the last line in the example below:
every item of c whose name is "other"
doesn't work -- it yields the error:
'Can't get { script, script, script } whose name = "other"'

Searching the the reference manual, I see that indeed, the Filter reference form
on a list is not valid.

Is it possible to write a new collection object or handler which does support
that sort of access ?

What is the typical way of doing this sort of thing in Applescript ?

( At this point, I'm probably going to try a collection script object that keeps a list
of keys and several sets of value lists -- with a handler that find the index of the desired
key name and returns that index item from one of the value lists. )

-- Steve Majewski





script Thing
property parent : {}
property name : missing value
property value : missing value
property properties : {name:a reference to my name, value:a reference to my value} ,

to New(n, v)
copy me to tmp
set tmp's name to n
set tmp's value to v
set tmp's properties to {name:n, value:v}
return tmp
end New
end script


set c to {Thing's New("aThing", 10), ,
Thing's New("bThing", 20), Thing's New("other", 0)}


properties of last item of c
every item of c whose name is "other"
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Breaking up a long string
      • From: Joseph Weaks <email@hidden>
    • Re: key,value pairs
      • From: Malcolm Fitzgerald <email@hidden>
  • Prev by Date: Re: Why save text item delimiters? Philosophical question....
  • Next by Date: Re: Why save text item delimiters? Philosophical question....
  • Previous by thread: Re: Path string interpretation with 'as alias'
  • Next by thread: Re: key,value pairs
  • Index(es):
    • Date
    • Thread