+
|
addition
|
-
|
subtraction
|
*
|
multiplication
|
/
|
division
|
Each of these operators requires two operands. When two
operands for an arithmetic expression are of different number
classes, one operand may be promoted internally to accommodate
the range of the other class.
In these examples, string addition and subtraction
convert the original
string, an instance of the class x
, which is an ImmediateInteger
object. The getClass
method is defined by
RootObject
, the root class from which all ScriptX
classes inherit, so it is available to all objects.global x:2, y:3.5, z:123.456789, w:9876543210, a, b, c
getClass x
ImmediateInteger
getClass y
ImmediateFloat
getClass z
Float
getClass w
LargeInteger
a := x + y
5.5
getClass a
ImmediateFloat
b := x + z
125.456789
getClass b
Float
c := x + w
9876543212
getClass c
LargeInteger
global p:3.23, q:4.23, resultObject
getClass p
ImmediateFloat
getClass q
ImmediateFloat
resultObject := p - q
1
getClass resultObject
ImmediateInteger
String Arithmetic
"this" + "that"
"thisthat"
"Once upon " + "a time"
String subtraction removes the first instance of the second
string operand from the first:"Once upon a time"
"one two three" - "one"
" two three"
"banana" - "an"
"bana"
The following code illustrates an easy way to print out the
value of a variable. Note that the parentheses are necessary
and that the integer x must be coerced to a
String
object in order to be added to another
string.x := 10
print ("x: "+ x as String)
"x: 10"
myFilename := "Answers.doc"
myPrefix := myFilename - ".doc"
"Answers"
StringConstant
,
into an instance of the class
String
(its editable counterpart).
StringConstant
is a subclass of
String
.
Operations that specifically test for an object's class may
not consider String
and StringConstant
to be the same, even though
they are both strings.
This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.