Chapter 14. Coercions
A coercion
is a conversion of a value of one datatype to a value of another datatype. In AppleScript, not just any old value can be turned into a value of just any old datatype. To put it more strictly: for some pairs of datatype, call them Datatype A and Datatype B, it is the case that at least some values of Datatype A can be coerced to a value of Datatype B. For example, the string "30"
can be coerced to a number; when that happens, you get the number 30
. There are other strings that can be coerced to other numbers, and there are strings that can't be coerced to any number at all. This implies that there is some sort of equivalence or formula that determines the new value given the old value. This chapter presents these equivalences for every pair of datatypes, describing what coercions are possible and the rules by which they are performed.
The discussion is confined almost entirely to AppleScript's native datatypes (listed in Chapter 13). Coercions between these datatypes are defined by the language. Coercions between nonnative datatypes, or between a native datatype and a nonnative datatype, must be implemented by the application that defines the nonnative type. Applications do this, if they do it at all, on an individual basis, so no documentation is possible here. Additional coercions of native (and other) types can be implemented by scripting additions (Chapter 21), but these are not discussed here either.
Implicit Coercion
Implicit coercion is performed ...
Get AppleScript: The Definitive Guide, 2nd Edition 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.