Walrus/Language
Method Calls
Function calls, closure calls, instance methods, and field access in Walrus.
Updated April 13, 20262 min readWalrus / Calls
Walrus supports ordinary function calls, closure calls, and class methods.
Function calls
Walrus
fn abs(x: int) -> int:
if x < 0:
return 0 - x
return x
fn main() -> int:
return abs(-3)Calling closures
Walrus
fn makeAdder(k: int) -> fn(int) -> int:
fn add(x: int) -> int:
return x + k
return add
fn main() -> int:
let add7 = makeAdder(7)
return add7(5)Calling methods
Instance methods use the same call syntax:
Walrus
class Actor:
var hp: int = 100
fn alive() -> bool:
return hp > 0
fn main() -> int:
let actor = Actor { }
if actor.alive():
return actor.hp
return 0Property access
This expression:
Walrus
state.xis a field lookup on an object or instance value. It is not the same operation as a function call even if both use dot syntax nearby.