Walrus/Language

Syntax

Core Walrus syntax for modules, statements, blocks, literals, comments, and typed declarations.

Updated April 13, 20263 min readWalrus / Syntax

Walrus uses a compact typed surface syntax with explicit module headers and colon-delimited blocks.

File structure

Most source files start like this:

Walrus
module Showcase
@strict
import Math
import Gameplay

Then come module constants, type declarations, and functions.

Comments

Walrus supports two comment forms:

Walrus
# single line comment

<#
block comment
#>

Statements

Common statement forms are:

  • let for local or module constants
  • var for mutable locals
  • assignment
  • if / else
  • while
  • switch / case / default
  • return
  • nested fn declarations inside functions
  • expression statements

Example:

Walrus
fn main() -> int:
    let total = 0
    var i = 0

    while i < 10:
        if i == 5:
            i += 1
        else:
            total += i
            i += 1

    return total

Types

Builtin type names are lowercase:

  • int
  • float
  • bool
  • string

Walrus also uses explicit function and ownership-aware types:

Walrus
fn makeAdder(k: int) -> fn(int) -> int
let view: ref string = text
let sharedNode: shared<UiNode> = uiRoot

Literals and expressions

Supported literal forms include:

  • integers like 0, 42, -3
  • floats like 2.0, 3.1415926
  • strings like "walrus says hi"
  • booleans true and false
  • arrays like [1, 2, 3]
  • object literals like { x = 1, y = 2 }
  • enum members like Team.Red

Common operators:

  • arithmetic: +, -, *, /
  • compound assignment: +=, -=
  • comparisons: ==, <, <=, >, >=
  • logical and: &&
  • indexing: a[i]
  • property access: o.x
  • calls: f(1, 2)