Expressions and Messages
All the statements will contain one, or more expressions.
There are no native operators, and all expressions are either mentions of an object, or messages sent to them.
Messages
There are three different semantics for messages
-
Unary Messages -- These are more than one unicode code point long, and take no parameters, and have no colon after them.
-
Binary Messages -- These are either exactly one unicode code point long, or are equal to
::
, or are composed of any of=+-*&%$@~<>?;
. these take a single argument. -
Keyword Messages -- These are arbitrarily long names, separated by colons
Examples for each follow:
- Unary:
2 sin
or2 toString
or'test' reverse
- Binary:
2 + 3
orTrue | False
or'te%st' % ['s']
- Keyword:
2 between: 0 and: 3
orTrue either: blk0 or: blk1
orArray join: ', '
Basic messages for the Number objects
-
Binary
+
- Adds something to a number
- Normally operates on Strings and Numbers
3 + 5
gives8
.3 + 'test'
gives'3test'
- Note that in no possible scenario a string would be implicitly cast to a number.
- Adds something to a number
-
Binary
-
- Subtracts a number from another
10 - 8
gives2
-
Binary
*
- Multiplies a number by another
2 * 3
gives6
-
Keyword
pow:
- raises a number to a numeric power
2 pow: 3
gives8
Tip:
To see all the Number methods, type :!m Number
in the interactive interpreter
Comparing two numbers
The method names are >
, <
, >=:
, <=:
, =
, !=:
equality can be tested with the alias method equals:
, However, when overriding equality, only =
must be overridden.
Shortcuts for number manipulations
The methods +=:
, *=:
, -=:
, /=:
exist, but they change the object itself, so any instance of that object will have a different value.
var a is 123.
var b is a.
a -=: 3.
Pen writeln: b. #Prints 120
Evaluation Order
The generic order of evaluation is
- The receiver
- The first argument (if present)
- The second argument (if present)
- and so on
Parens are treated normally.