• 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: can I make a list of records?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can I make a list of records?


  • Subject: Re: can I make a list of records?
  • From: Nigel Garvey <email@hidden>
  • Date: Mon, 28 Jan 2002 18:46:00 +0000

James Sentman wrote on Mon, 28 Jan 2002 11:28:14 -0500:

>Hi Folks,
>
>I'd like to be able to represent some data structures as lists of
>records so that I can do things like
>
>set myFirstRecord to {name:"jack", age:"32"}
>set mySecondRecord to {name:"peter", age:"41"}
>
>and then put them into a single list, but make it a list of records,
>not just a list of strings which is what I always seem to get.
>
>set MyList to MyList & MyFirstRecord & MySecondRecord just gives me a
>regular list of strings with 4 items in it.

This is to do with AppleScript's rules for concatenation. Only similar
items can be concatenated together, so when you concatenate two items of
different classes, the item to the right of the ampersand is first
coerced to the same class as the item on the left, if possible. If
they're totally incompatible, they're both coerced to lists. Assuming
that you initialised MyList as {}, concatenating a record to it causes
the record to be coerced to a list, with the result that the labels
disappear.

One way round this is to use a command which specifically puts items
*into* the list:

set the end of MyList to MyFirstRecord
set the end of MyList to MySecondRecord

Another possiblity that might be more convenient is:

set MyList to MyList & {MyFirstRecord} & {MySecondRecord}

This supplies the records already encased in lists, and it's these lists
that are concatenated.

NG


  • Prev by Date: Scripting Addition w/ Dialog Boxes (OS X)
  • Next by Date: Re: Early AS Sample Scripts [Was Re: AS Release Notes (was Re: Weird try block syntax)]
  • Previous by thread: Re: can I make a list of records?
  • Next by thread: Re: can I make a list of records?
  • Index(es):
    • Date
    • Thread