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

Operators

Operators are bits of code intended to control how the program runs.

puts

Stands for “put something”. Prints debug info to the console, followed by a new line.

Formatting

  • int: The literal number, as formatted by C printf("%" PRId64).

  • double: The literal number, as formatted by C printf("%f").

  • string: All characters in the string, as formatted by C printf("%s").

  • char: The ASCII character corresponding to the number held, as formatted by C printf("%c").

  • bool: If true or 1, print true. Otherwise, print false.

  • fun: Print <function>.

  • template: Print <struct fields: { ... }>, where:

    • ... is a comma-seperated sequence of key: value, where:
      • key is the identifier of the field.
      • value is the properly formatted value in the field.
  • object: Print <object fields: { ... }>, where:

    • ... is a comma-seperated sequence of key: value, where:
      • key is the identifier of the field.
      • value is the properly formatted value in the field.

if

Runs a block of code only if the provided condition is true.

Syntax:

if condition {
    ...
}

where:

  • condition is an expression which evaluates to a boolean.
    • If this expression evaluates to true, the code block will be run.
    • Brackets surrounding the condition are optional.
  • ... is the code to run if the condition is true.

Example:

if 2 + 2 == 4 {
    puts "phew!"
}

while

Runs a block of code until the provided condition is false.

Syntax:

while condition {
    ...
}

where:

  • condition is an expression which evaluates to a boolean.
    • If this expression evaluates to false, the code block will not be run anymore.
    • Brackets surrounding the condition are optional.
  • ... is the code to run while the condition is true.

Example:

while true {
    puts "To infinity and beyond!"
}

return

Returns a value from a function.

Syntax:

return value

where value is a value with the same type as the function’s return type.

ground

Inline Ground is potentially dangerous. Only use if you know what you’re doing!

Inserts inline Ground code into the generated program.

Syntax:

ground {
    ...
}

where ... is the Ground code to insert.

See here for details about Ground.

Note: Solstice cannot keep track of state inside ground blocks! Ground will allow you to do things without the overhead of the Solstice type checker.

To extract a value from a Ground block, do something like this:

x = 0
ground {
    set &x 10
}

puts x

so the type checker can know what x is.