Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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
  • -: 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
  • *: 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
  • /: 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)
    • 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

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:
      • true if both provided values are exactly the same.
      • false otherwise.
    • Precedence: 2
  • !=: 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:
      • true if both provided values are not exactly the same.
      • false otherwise.
    • Precedence: 2
  • >: Checks two numbers to determine which is greater
    • Accepts:
      • Any two numbers (int or double) either side
    • Returns:
      • true if the number provided on the left is greater than the number provided on the right.
      • false otherwise.
    • Precedence: 2
  • <: Checks two numbers to determine which is lesser
    • Accepts:
      • Any two numbers (int or double) either side
    • Returns:
      • true if the number provided on the left is lesser than the number provided on the right.
      • false otherwise.
    • Precedence: 2
  • >=: Checks two numbers to determine which is greater, or whether both are equal
    • Accepts:
      • Any two numbers (int or double) either side
    • Returns:
      • true if the number provided on the left is greater than the number provided on the right, or if both numbers are equal.
      • false otherwise.
    • Precedence: 2
  • <=: Checks two numbers to determine which is lesser, or whether both are equal
    • Accepts:
      • Any two numbers (int or double) either side
    • Returns:
      • true if the number provided on the left is lesser than the number provided on the right, or if both numbers are equal.
      • false otherwise.
    • Precedence: 2

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
  • .: 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

Brackets

  • (...): Evaluates an expression inside the brackets before outside expressions.
    • Accepts:
      • Any expression inside the brackets (in place of ...)
    • Returns:
      • The result of the expression in the brackets
    • Precedence: 7

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 ...)
    • Returns:

Unary Misc

  • new: Creates a new object from a template.
    • Accepts:
      • A template after the new keyword.
      • A core type identifier
    • 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: 0
        • double: 0.0
        • string: ""
        • char: '\0'
        • bool: false
  • sizeof: Gets the size of something.
    • Accepts:
      • A string
      • An object with an int size field
    • Returns:
      • The string length if provided a string
      • The int size field of the object if provided an object