Record
A record is an unordered collection of name-value pairs. The values may be of any type. A literal record looks like a literal list except that each item has a name. The name is separated from the corresponding value with a colon. So:
set R to {who:"Matt", town:"Ojai"}
There is no such thing as an empty record. A record has no
item
elements, its items cannot be referred to by
index number, and you can’t talk about the
beginning
or end
of a record.
You can assign a record of values to a literal record of variable names or other references as a shorthand for performing multiple assignment. The assignments are performed pairwise by name, independently. If the record of values includes names that aren’t in the record of variables, the extra values are ignored; if it’s missing any names that are in the record of variables, there’s a runtime error. See Section 7.1 and Section 13.12, earlier in this chapter. For example:
local who, town
set {who:who, town:town} to {town:"Ojai", who:"Matt"}
{who, town} -- {"Matt", "Ojai"}
When you
use set
(as opposed to copy
) to
set a variable to a value which is a record, you set the variable
by reference
. This means that the record is not
copied; the variable’s name becomes a new name for
the record, in addition to any names for the record that may already
exist. The same is true when a record is passed as a parameter to a
handler. This special treatment is in common between lists, records,
dates, and script objects. (See Section 8.4 and
Section ...
Get AppleScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.