AppleScript_ The Definitive Guide - Matt Neuburg [142]
Description
Yields true if the first operand is less than or equal to the first. Abbreviation is <=, or the ≤ symbol may be typed using Option-comma. Synonym is less than or equal to has abbreviations omitting is, to, or both. There are also synonyms does not come after and is not greater than.
Name
≥
Synopsis
greater than or equal to
greater than or equal to
Syntax
operand1 ≥ operand2
Description
Yields true if the first operand is greater than or equal to the second. Abbreviation is >=, or the ≥ symbol may be typed using Option-period. Synonym is greater than or equal to has abbreviations omitting is, to, or both. There are also synonyms does not come before and is not less than.
Containment Operators
The containment operators test whether the value of one thing is to be found "inside" the value of another. For example, the string "test" contains the string "e". Containment may apply to two strings, two lists, or two records. The result is a boolean.
Containment implies comparison, and the nature of comparisons involving strings can be influenced by a considering clause; see Chapter 19.
It is worth stressing that in the case of list containment, both operands must be lists. In other words, the second operand is not an element; it's a sublist. This is a little counterintuitive at first. To complicate matters, AppleScript fools you by apparently letting you say just what you (wrongly) think you should be allowed to say:
{1, 2} contains 2 -- true
You can say that, but not because it is correct on its face; it's because 2 is coerced to {2} implicitly to get the right syntax, which would be this:
{1, 2} contains {2} -- true
Because the second operand is a sublist, you can ask about more than one element at once:
{1, 2, 3} contains {2, 3} -- true
Lists are ordered, so the items of the sublist you ask about must appear consecutively and in the same order in the target list. These are false:
{1, 2, 3} contains {1, 3} -- false
{1, 2, 3} contains {3, 2} -- false
Because lists can contain lists, you may have to use an explicit extra level to say what you mean:
{{1}, {2}} contains {2} -- false
{{1}, {2}} contains {{2}} -- true
The first is false because 2 is not an element of the first list, and {2} is not going to be coerced to {{2}} for you—it's a list already, so there's nothing to coerce.
With regard to record containment, both the label and the value must match for containment to be true:
{name:"Matt", age:"51"} contains {name:"Matt"} -- true
{name:"Matt", age:"51"} contains {title:"Matt"} -- false
{name:"Matt", age:"51"} contains {name:"Socrates"} -- false
Records are not internally ordered:
{name:"Matt", age:"51"} contains {age:"51", name:"Matt"} -- true
For purposes of containment, the empty list is treated as the empty record:
{name:"Matt", age:"51"} contains {} -- true
{} contains {name:"Matt", age:"51"} -- false
Because the containment operators are overloaded to apply to both strings and lists, the first operand is never implicitly coerced to a string, because AppleScript can't know that this is what you mean; it is coerced to a list unless it is a string (or record). The second operand is then coerced to match the datatype of the first. For example:
"51" contains 5 -- true; string containment, "51" contains "5"
51 contains 5 -- false; list containment, {51} doesn't contain {5}
It's important not to confuse the implicit coercion rules here with those for certain other operators. For example, your experience with arithmetic operators might lead you to expect a certain kind of implicit coercion:
{"7"} * 7 -- 49
The list of a single string is coerced to a single string and from there to a number. But that isn't going to happen with contains:
{"7"} contains 7 -- false
The first operand isn't coerced at all; the second operand is coerced to {7}, and that's the end. The second operand isn't a sublist of the first, so the comparison is false.
Do not rely on implicit coercion of nonnative classes to a list; it usually doesn't work.