Description
List
operator; specifies that the entries within the brackets are one
of four types of lists:
Unsorted linear lists
Sorted linear lists
Unsorted property lists
Sorted property lists
Each entry in a linear
list is a single value that has no other property associated with
it. Each entry in a property list consists of a property and a value.
The property appears before the value and is separated from the
value by a colon. You cannot store a property in a linear list.
When using strings as entries in a list, enclose the string in quotation
marks.
For example, [6, 3, 8] is a linear list. The numbers
have no properties associated with them. However, [#gears:6, #balls:3,#ramps:8]
is a property list. Each number has a property—in this case, a type
of machinery—associated with it. This property list could be useful
for tracking the number of each type of machinery currently on the
Stage in a mechanical simulation. Properties can appear more than
once in a property list.
Lists can be sorted in alphanumeric
order. A sorted linear list is ordered by the values in the list.
A sorted property list is ordered by the properties in the list.
You sort a list by using the appropriate command for a linear list
or property list.
In linear lists, symbols and strings
are case sensitive.
In property lists, symbols aren’t case-sensitive, but strings
are case-sensitive.
A linear list or property
list can contain no values at all. An empty list consists of two
square brackets ([ ]). To create or clear a linear list, set the
list to [ ]. To create or clear a property list,
set the list to [:].
You can modify, test, or read items in
a list.
Lingo treats an instance of a list as a reference
to the list. This means each instance is the same piece of data,
and changing it will change the original. Use the duplicate command
to create copies of lists.
Lists are automatically disposed
when they are no longer referred to by any variable. When a list
is held within a global variable, it persists from movie to movie.
You
can initialize a list in the on prepareMovie handler
or write the list as a field cast member, assign the list to a variable,
and then handle the list by handling the variable.
Not all
PC keyboards have square brackets. If square brackets aren’t available, use
the list function to create a linear list.
For
a property list, create the list pieces as a string before converting
them into a useful list.
myListString = numToChar(91) & ":" & numToChar(93)
put myListString
-- "[:]"
myList = myListString.value
put myList
-- [:]
put myList.listP
-- 1
myList[#name] = "Brynn"
put myList
-- [#name: "Brynn"]
Example
This
statement defines a list by making the machinery variable
equal to the list:
-- Lingo syntax
machinery = [#gears:6, #balls:3, #ramps:8]
// JavaScript syntax
var machinery = propList("gears",6, "balls",3, "ramps",8);
This
handler sorts the list aList and then displays the result in the
Message window:
-- Lingo syntax
on sortList aList
alist.sort()
put(aList)
end sortList
// JavaScript syntax
function sortList(aList) {
aList.sort();
put(aList);
}
If the movie issues the statement sortList machinery,
where machinery is the list in the preceding example,
the result is [#balls:3, #gears:6, #ramps:8].
The
following statements create an empty linear list:
-- Lingo syntax
x = [ ]
x = list()
// JavaScript syntax
var x = list();
The following statements create an
empty property list:
-- Lingo syntax
x = [:]
x = propList()
// JavaScript syntax
var x = propList();