Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [141]

By Root 1427 0

Name

^

Synopsis

exponentiation

exponentiation

Syntax

number1 ^ number2

Description

Raises the first number to the power of the second. The result is a real.

Boolean Operators


The boolean operators implement the basics of logic, working on boolean operands to produce a boolean result. The second operand, but not the first, will be coerced from a string or an integer, or a list of one string or one integer, to a boolean. Either operand will be coerced from a list of one boolean to a boolean.

Name

and

Synopsis

logical and

logical and

Syntax

boolean1 and boolean2

Description

Returns true if both operands are true. If the first operand is false, the second operand won't even be evaluated ("short-circuiting").

Name

or

Synopsis

logical or

logical or

Syntax

boolean1 or boolean2

Description

Returns false if both operands are false. If the first operand is true, the second operand won't even be evaluated ("short-circuiting").

Name

not

Synopsis

logical not

logical not

Syntax

not boolean

Description

Changes true to false and false to true.

Comparison Operators


The comparison operators test whether one operand is the same as the other, or whether, if they can be ordered, they are ordered in a given direction. The result is a boolean.

The nature of comparisons involving strings can be influenced by a considering clause; see Chapter 19.

Lists are internally ordered, but records are not:

{1, 2} = {2, 1} -- false

{name:"Matt", age:"51"} = {age:"51", name:"Matt"} -- true

The equality (=) and inequality (≠) operators do not coerce their operands; operands may be of any datatype, and operands of different datatypes are unequal. So:

{"2"} = 2 -- false

In that example, the first operand is a list, the second operand is a number, and no coercion takes place. So the operands are not equal, and the comparison is false.

With the other comparison operators , operands must ultimately be a string, a number, or a date. The first operator is coerced to a string, a number, or a date, and then the second operator is coerced to match the datatype of the first:

{"2"} ≥ 2 -- true

In that example, the first operand is a list of one string, so it is coerced to a string. Now the second operand is coerced to a string; the two strings are equal and the comparison is true.

Thus, although you cannot use the equality operator to learn whether two values would be equal if implicitly coerced to the same datatype, you can work around the problem like this:

{"2"} ≤ 2 and {"2"} ≥ 2 -- true

As noted in "Assignment and Retrieval" in Chapter 7, the equality operator is not overloaded as an assignment operator. This code will compile and run, but it won't assign 4 to x (it will report whether they are equal):

x = 4

Name

= (is)

Synopsis

equality

equality

Syntax

operand1 = operand2

Description

Yields true if the operands are equal. No coercion is performed; different datatypes are not equal. Synonym is equal to has abbreviations equal, equals, and equal to.

Name

≠ (is not)

Synopsis

inequality

inequality

Syntax

operand1 ≠ operand2

Description

Yields true if the the operands are unequal. No coercion is performed; different datatypes are not equal. The not-equals sign is typed using Option-=. is not has abbreviation isn't. Synonym is not equal to has abbreviations is not equal, isn't equal, does not equal, and doesn't equal. There are no synonyms <> or !=.

Name

<

Synopsis

less than

less than

Syntax

operand1 < operand2

Description

Yields true if the first operand is less than the first. Synonyms are is less than (abbreviation less than) and comes before.

Name

>

Synopsis

greater than

greater than

Syntax

operand1 > operand2

Description

Yields true if the first operand is greater than the first. Synonyms are is greater than (abbreviation greater than) and comes after.

Name

Synopsis

less than or equal to

less than or equal to

Syntax

operand1 ≤

Return Main Page Previous Page Next Page

®Online Book Reader