Using Subexpressions
As in C, of course, users can use subexpressions as part of larger expressions. For example, you can use a mathematical expression as part of a method call, or a method call as part of a mathematical expression. Because of the syntax of steve , however, subexpressions frequently need to be parenthesized in situations where it would not be required in C. The following important rules apply to using subexpressions: If a method call is not the entire statement, it must be parenthesized. If you wish to assign the result of a method call, use it in a mathematical expression or use it as an argument for another method, for example:
myInt = self get-speed. # incorrect myInt = (self get-speed). # correct myInt = self get-speed + 5. # incorrect myInt = (self get-speed) + 5. # correct self set-speed to neighbor get-speed. # incorrect self set-speed to (neighbor get-speed). # correct
All method arguments must be a single "unit"—arguments which are not simply a variable or literal value must be parenthesized.
This means that if you use mathematical expressions, instantiations or other method calls as input arguments to a method, they must be parenthesized. The first rule about method calls, of course, still applies:
self set-location to ((neighbor get-location) + (10, 10, 10)). # correct self set-location to (neighbor get-location) + (10, 10, 10). # incorrect
