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 GameplayThen come module constants, type declarations, and functions.
Comments
Walrus supports two comment forms:
Walrus
# single line comment
<#
block comment
#>Statements
Common statement forms are:
letfor local or module constantsvarfor mutable locals- assignment
if/elsewhileswitch/case/defaultreturn- nested
fndeclarations 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 totalTypes
Builtin type names are lowercase:
intfloatboolstring
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> = uiRootLiterals and expressions
Supported literal forms include:
- integers like
0,42,-3 - floats like
2.0,3.1415926 - strings like
"walrus says hi" - booleans
trueandfalse - 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)