Property Lists
Property lists are similar to lists, as both property lists and lists are collections of values. The fundamental difference is that a list is a simple sequence of values, while each value in a property list is identified by a name or label, called its key. For more information about working with property lists, see Property List Operators.
Example:
put {x:5,y:12} into myPropList // This property list includes two keys, x and y, and two values, 5 and 12, respectively.
Another difference, which is less obvious but can be even more significant, is that a property list is the simplest form of a SenseTalk object, which means it has behaviors as well as properties. The remainder of this section explains property lists primarily as data containers. For complete information about objects, see Objects and Messages.
Lists and property lists can be passed as parameters. For information on passing lists or property lists as parameters, see Parameters and Results.
Creating Property Lists
To create a property list, enter the keys and values for each of its properties, and enclose it in curly brackets . Each property’s key precedes its associated value, separated by a colon, with key/value pairs separated by commas.
Prior to SenseTalk 2.00 (Eggplant Functional 20.1), both lists and property lists used parentheses () by default instead of square brackets [] or curly braces (respectively). Parentheses are still considered valid syntax for property lists, but their use is not recommended as it can lead to confusion.
Example:
put {name:"Elizabeth", age:14} into daughter
To specify an empty property list, use an empty pair of curly braces {}
, a colon in curly braces{:}
, or the phrase empty object
or empty property list
.
Example:
put {:} into newPlist
A property list (because it is an object) can be helped by other objects, such as objects defined in text files.
Example:
put {name:"Hank", age:47} helped by parent,actor into candidate
Property lists can span multiple lines without the need to use line continuation (“\”) characters:
set detective to {name: "Sherlock Holmes",
address: "221 B Baker Street, London",
remarks: "Enjoys playing violin, solving mysteries"}
A property list can also use parentheses () instead of curly braces . When using parentheses, the entire property list must appear on a single line:
Example:
put (beverage: "milk", food: "chocolate chips") into groceries
When a property list occurs as the last item of a regular list, you can omit the curly braces from around the property list. This approach yields a syntax that has the appearance of a list/property list hybrid, but the named properties must come at the end. The following two lines are equivalent:
Examples:
put [5, 12, {color:"Green", size:42}] --> [5,12,{color:"Green", size:42}]
put [5, 12, color:"Green", size:42] --> [5,12,{color:"Green", size:42}]
Property Keys
All property names (keys) are text strings. Property keys can be entered without any special treatment if the property name: (a) begins with an alphabetic character or an underscore; and (b) contains only alphabetic characters, digits, and underscores. To use a key that contains spaces or special characters, or that begins with a digit, you must enclose the key in quotes.
Example:
set oddPlist to {alpha:"ok", "87":"four score and seven", "$":50}