[ Team LiB ] |
Chapter 15. OperatorsAn operator is a token that transforms a value or a pair of values into a new value. These transformations are operations, and the values operated upon are the operands. An operator with two operands is binary; an operator with one operand is unary. That definition is pretty good, but it doesn't quite pick out what this chapter catalogues. Parentheses are also discussed here, because they determine the effects of the other operators; and some of the things I'm calling operators are thought of by AppleScript as language keywords. (For the coercion operator, as, see Section 14.2; for the object containment operator, of, see Chapter 10.) Binary operators can perform a limited range of implicit coercions. AppleScript's behavior in this regard is odd, and the error messages that result when a binary operator refuses to perform an implicit coercion are confusing. For example, if you say: 1 and 1 -- compile-time error the compile-time error message says: "Can't make 1 into a boolean." But AppleScript can make 1 into a boolean, as you can prove by asking it to do so: 1 as boolean and 1 -- true
In that example, AppleScript refuses to coerce the first operand implicitly, but it happily coerces the second operand implicitly. But in this next example, AppleScript happily coerces both operands implicitly (to a number): "3" + "4" -- 7
This chapter catalogues the rules governing this behavior. To learn what can be coerced to what in AppleScript, see Chapter 14. |
[ Team LiB ] |