Skip to content

Keywords

Conditionals

Functions

  • fn: This is a function definition.
  • try: This is a keyword that is required to call a function that may throw. It doesn't do anything specific on its own, however it makes it clear to someone reading the code that the function they're calling could throw. It also colors the function it's being called in, and that containing function also becomes a throwing function. See error handling for details.
  • catch: This is a keyword that allows you to catch an error returned by a function without needing to declare it as a variable and handling it on a separate line. It only works for functions with the type fn(...) -> (..., error) See error handling for details.
  • return: This is used to return values from a function.

Types

  • bool: This is a builtin type for booleans.
  • byte: This is a builtin type for bytes.
  • char: This is a builtin type for characters.
  • enum: This is a keyword for defining enums.
  • error: This is a builtin type for errors.
  • int, uint: These are builtin types for integers.
  • rat: This is a builtin type for rational numbers.
  • str: This is a builtin type for strings.
  • struct: This is a keyword for defining structs.
  • type: This is a keyword for defining types.
  • mut: This keyword allows a value to be mutable. It can be used with any type.
  • as: This keyword allows a value to be cast into another type.

Loops

  • for, in: These are used in for loops. The for signifies that it's a for loop, the value before in creates a variable that gets the value for each iteration of the loop, and the value after in is the array over which the loop is iterating.
  • while: This is used in while loops. The while signifies that it's a while loop, and the condition after while is checked each time the loop is run. If the condition is true, the loop continues, if not, it breaks and the program continues execution after the loop.
  • break, continue: These are used to break and continue loops, and can optionally be used with labels. See Labels, break, and continue.

Modules

  • import, as: This keyword allows you to import symbols from modules such as other files or libraries, and assign them to a given module name.
  • pub: This keyword allows you to export symbols from a module to be used in other places.

Operators

Async

  • async: This marks a function call as asynchronous, and returns a Future. See async for details.
  • await: This awaits a Future to block execution until it resolves and gets a value out. See async for details.
  • lock: This locks a Mutex and makes it mutable so only one thread can access and mutate it. If a thread has a lock, all other threads must wait until the lock is released and they can get their own lock.
  • unlock This unlocks a Mutex and makes it immutable so all threads can read from it.

Testing

  • test: This keyword allows you to define tests for your code.