• 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 -- improved
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting a record item with a string key -- improved


  • Subject: Getting a record item with a string key -- improved
  • From: Olof Hellman <email@hidden>
  • Date: Wed, 10 Oct 2001 12:29:48 -0700

Here's a variant that works around the issues of canonicalization of
variable names, so that you can use uppercase and multi word tags in your
dynamically built-from-string records, as was originally requested by
Harald:


to extract_exact_usrf(theRecord, fieldName)
script Fred
property r : theRecord
to extract()
end extract
end script

set Amy to run script "script George
property r : {}
to extract()
return |" & fieldName & "| of r -- note the bars!!
end extract
end
George"

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

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

set usrfRecord to usrf({"EU", 3, "b", 2})
-->{|EU|:3, b:2}

-- now use the string "EU" to get record item |EU|
extract_exact_usrf(usrfRecord, "EU")
--> 3


Note that you'll still need the previous version if you want to do

set aRecord to {EU: 3, b: 2}
-->{EU:3, b:2}
-- not built with usrf() , so the record tag is EU, not |EU|

-- now use the string "EU" to get record item EU
extract_usrf(usrfRecord, "EU")
--> 3


- Olof


  • Prev by Date: Re: Updating scripts/applets company-wide
  • Next by Date: copy files from alias'
  • Previous by thread: Re: Updating scripts/applets company-wide
  • Next by thread: copy files from alias'
  • Index(es):
    • Date
    • Thread