• 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: Listing the names contained in a record
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Listing the names contained in a record


  • Subject: Re: Listing the names contained in a record
  • From: Gakuji Ohtori <email@hidden>
  • Date: Thu, 31 Oct 2002 03:26:26 +0900

On 2002.10.30, at 05:37 PM, John Delacour wrote:

At 1:28 am -0600 30/10/02, Jeffrey Mattox wrote:

Is there a way to get a list of the names of the name/value pairs in a record?

If you are responsible for creating the record, then instead of creating a record, create a list and use the odd-numbered items for the keys and the even-numbered for the values. Here's an example I posted a couple of weeks ago:



set {key_, value_} to {"key1", false}
set array_ to {"key1", "value1", "key2", "value2"}
repeat with i from 1 to count array_
if i mod 2 is 1 then
if item i of array_ is key_ then
set value_ to item (i + 1) of array_
exit repeat
end if
end if
end repeat
if value_ is not false then return value_

I would use a list of records instead of a flat (1 dimentional) list:

set theRecList to {{k:"a", v:1}, {k:"b", v:2}, {k:"c", v:3}}
set theKeyList to {}
repeat with eachItem in theRecList
set end of theKeyList to k of contents of eachItem
end repeat
return theKeyList

--> {"a", "b", "c"}

By the way, "every item" seems to extract all values from a record:

set r to {a:1, b:2, c:3}
every item of r

--> {1, 2, 3}

I couldn't find the way to extract the list of labels ({a, b, c} in the example above) from a record. Does anyone know?

Gaji
_______________________________________________
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.

References: 
 >Re: Listing the names contained in a record (From: John Delacour <email@hidden>)

  • Prev by Date: Failed Attempts to BCC with Outlook
  • Next by Date: Re: Failed Attempts to BCC with Outlook
  • Previous by thread: Re: Listing the names contained in a record
  • Next by thread: Re: Listing the names contained in a record
  • Index(es):
    • Date
    • Thread