Expressions
An expression in Solstice is a combination of operators and values (whether literal or stored in a variable).;
Expression Types
“Precedence” is a number which dictates the order of execution. The higher the precedence, the sooner an expression will be evaluated.
Binary Mathematical
+: Adds two numbers on either side, or concatenates two strings- Accepts:
- Two integers either side
- Two doubles either side
- Two strings either side
- An integer and a double on either side (order not significant)
- Returns:
- The sum of both values as an integer if both values are integers
- The sum of both values as a double if one value is a double and the other is an int, or both values are doubles
- The concatenated string when both values are strings
- Precedence: 5
- Accepts:
-: Subtracts two numbers on either side- Accepts:
- Two integers either side
- Two doubles either side
- An integer and a double on either side (order not significant)
- Returns:
- The difference of both values as an integer if both values are integers
- The difference of both values as a double if one value is a double and the other is an int, or both values are doubles
- Precedence: 5
- Accepts:
*: Multiplies two numbers on either side- Accepts:
- Two integers either side
- Two doubles either side
- An integer and a double on either side (order not significant)
- Returns:
- The product of both values as an integer if both values are integers
- The product of both values as a double if one value is a double and the other is an int, or both values are doubles
- Precedence: 6
- Accepts:
/: Divides two numbers on either side- Accepts:
- Two integers either side
- Two doubles either side
- An integer and a double on either side (order not significant)
- Two doubles either side
- Two integers either side
- Returns:
- The quotient of both values as an integer if both values are integers
- The quotient of both values as a double if one value is a double and the other is an int, or both values are doubles
- Precedence: 6
- Accepts:
Binary Comparative
==: Checks two values to determine if they are equal- Accepts:
- Any two values either side which are of the same type
- An integer and a double on either side (order not significant)
- Returns:
trueif both provided values are exactly the same.falseotherwise.
- Precedence: 2
- Accepts:
!=: Checks two values to determine if they are not equal- Accepts:
- Any two values either side which are of the same type
- An integer and a double on either side (order not significant)
- Returns:
trueif both provided values are not exactly the same.falseotherwise.
- Precedence: 2
- Accepts:
>: Checks two numbers to determine which is greater- Accepts:
- Any two numbers (int or double) either side
- Returns:
trueif the number provided on the left is greater than the number provided on the right.falseotherwise.
- Precedence: 2
- Accepts:
<: Checks two numbers to determine which is lesser- Accepts:
- Any two numbers (int or double) either side
- Returns:
trueif the number provided on the left is lesser than the number provided on the right.falseotherwise.
- Precedence: 2
- Accepts:
>=: Checks two numbers to determine which is greater, or whether both are equal- Accepts:
- Any two numbers (int or double) either side
- Returns:
trueif the number provided on the left is greater than the number provided on the right, or if both numbers are equal.falseotherwise.
- Precedence: 2
- Accepts:
<=: Checks two numbers to determine which is lesser, or whether both are equal- Accepts:
- Any two numbers (int or double) either side
- Returns:
trueif the number provided on the left is lesser than the number provided on the right, or if both numbers are equal.falseotherwise.
- Precedence: 2
- Accepts:
Binary Misc
as: Converts between types.- Accepts:
- Any object on the left, and a type which has an applicable conversion defined by the object on the right
- Returns:
- The object turned into the type on the right, in the way defined by the as-method
- Accepts:
.: Accesses object fields- Accepts:
- An object on the left, and an identifier on the right which corresponds to a field or method in the object
- Returns:
- The object field or method the identifier corresponds to
- Accepts:
Brackets
(...): Evaluates an expression inside the brackets before outside expressions.- Accepts:
- Any expression inside the brackets (in place of
...)
- Any expression inside the brackets (in place of
- Returns:
- The result of the expression in the brackets
- Precedence: 7
- Accepts:
Function Call
(...): Calls the specified function.- Accepts:
- An identifier for the function before the brackets, then comma-seperated expressions corresponding to the function type signature (see Types -> Combined Types -> fun) inside the brackets (in place of
...)
- An identifier for the function before the brackets, then comma-seperated expressions corresponding to the function type signature (see Types -> Combined Types -> fun) inside the brackets (in place of
- Returns:
- The function’s return type as specified by the function type signature (see Types -> Combined Types -> fun)
- Accepts:
Unary Misc
new: Creates a new object from a template.- Accepts:
- A template after the
newkeyword. - A core type identifier
- A template after the
- Returns:
- An object based on the provided template, if provided with a template.
- The empty version of the core type, if provided with a core type, which is:
int:0double:0.0string:""char:'\0'bool:false
- Accepts:
sizeof: Gets the size of something.- Accepts:
- A string
- An object with an
int sizefield
- Returns:
- The string length if provided a string
- The
int sizefield of the object if provided an object
- Accepts: