This repository was archived by the owner on May 21, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Operators
Austin Lehman edited this page Oct 23, 2022
·
1 revision
Math Operators:
// Addition
myVar = 5 + 10; // myVar is 15.
// Subtraction
myVar = 10 - 5; // myVar is 5.
// Multiplication
myVar = 10 * 5; // myVar is 50.
// Division
myVar = 10 / 5; // myVar is 2.
// Plus equals. (myVar currently 10.)
myVar += 5; // myVar is 15.
// Minus equals. (myVar currently 10.)
myVar -= 5; // myVar is 5.
// Multiply equals. (myVar currently 10.)
myVar *= 5; // myVar is 50.
// Divide equals. (myVar currently 10.)
myVar /= 5; // myVar is 2.
// Plus plus. (myVar currently 10.)
myVar++; // myVar is 11.
// Minus minus. (myVar currently 10.)
myVar--; // myVar is 9.
String Concatenation:
// String concatenation uses + operator.
myVar = "Make " + "soap."; // myVar should be 'Make soap'.
// String + anything else converts the other item to a string.
myVar = "My age is " + 32; // myVar should be 'My age is 32'.
// Grouping expressions within parenthesis will cause the expression within the
// parenthesis to be evaluated first.
myVar = "My age is " + (20 + 12) + "."; // myVar should be 'My age is 32.'.
Collection Operators:
// @= is used to append to a list.
myList @= "new value";
// # is the count operator and can be used on maps and lists.
numElements = #myList;
And within the class definition, maps and lists can be assigned starting values using the following syntax.
class myClass {
public languages = ['c', 'c++', 'java', 'aussom'];
public myMap = {
'one' : 1,
'two' : 2,
'three' : 3,
'four' : ['a', 'b', 'c'],
'five' : { 'make' : 'soap' }
};
// ...
public someFunct() {
tmp = 'three';
newmp = {'one': 1, 'two': 2, tmp: 3, 'four': [1, 2, 3, 'tyler'] };
newmp['five'] = resultOfSomeMethod();
}
}
Note: Within the class definition member maps and lists can only be defined with primitive types as shown above. When defining members you cannot say call a method and the result be a value in a map.
Callback Operator:
// Double colon operator with a following function name is they proper syntax
// for creating a callback item. They can be stored in variables and passed
// to functions just like other data types.
myCallback = ::someFunction;