• 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
Getting a record item with a string key -- a "real programmer" kind of hack
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting a record item with a string key -- a "real programmer" kind of hack


  • Subject: Getting a record item with a string key -- a "real programmer" kind of hack
  • From: Olof Hellman <email@hidden>
  • Date: Tue, 09 Oct 2001 14:45:05 -0700

It has been suggested that the usrf method is useless without the reverse
operation, i.e. not just making the list, but getting items out of the list.
List Guy posted Neal Crocker's object-specifier based version. I think this
one is easier to grok, although it uses one of the worst features of
AppleScript ( i.e. handler assignment inside a script object ):


to usrf(theList)
script
{+class usrf;:theList}
end script
run script the result
end usrf

to extract_usrf(theRecord, fieldName)
script Fred
property r : theRecord
to extract() -- supply a dummy method
end extract
end script

set Amy to run script "script George
property r : {}
to extract()
return " & fieldName & " of r
end extract
end
George"

set Fred's extract to Amy's extract
return (Fred's extract())
end extract_usrf


set usrfList to usrf({"a", 1, "b", 2})
-->{a:1, b:2}

-- now use the string "b" to get b
extract_usrf(usrfList, "b")
--> 2


  • Prev by Date: Re: EU as text (Was: Coercion of a string to a record label?)
  • Next by Date: URL Access Scripting and MacBinary?
  • Previous by thread: Re: EU as text (Was: Coercion of a string to a record label?)
  • Next by thread: URL Access Scripting and MacBinary?
  • Index(es):
    • Date
    • Thread