Language / Operators

Operators

Silk’s operators cover arithmetic, comparisons, logical operators, assignment, casts, ranges, optionals (?., ??), and typed-error propagation (?).

This wiki page is a learning-oriented companion to the canonical reference: operators.

Notes#

Syntax#

let a: int = 10;
let b: int = 3;

let sum: int = a + b;
let cmp: bool = a >= b;

// Optional chaining and coalescing
// let email: string = user.profile?.email ?? "no-email";

// Casts
let x: u64 = 123 as u64;

// Typed-error propagation
// let value: T = may_panic()?;

Examples#

Example: arithmetic + comparisons#

fn main () -> int {
  let a: int = 10;
  let b: int = 3;
  if a % b == 1 {
    return a + b; // 13
  }
  return 0;
}

Example: ?? coalescing#

fn main () -> int {
  let x: int? = None;
  return x ?? 42;
}

See also#

Source repository · Edit this page · View Markdown