-- basic declarationfngreet(name){println("Hello, {name}!")}greet("world")-- expression body shorthandfndouble(x)=x*2println(double(5))-- implicit return (last expression)fnsquare(x){x*x}println(square(4))-- with type annotationsfnadd(a:int,b:int)->int{returna+b}println(add(3,4))
fn main() is auto-called if defined. In scripts without a main, the top-level code runs directly.
-- @test: marks the function as a test case (run by xs test)@testfntest_add(){assert_eq(1+2,3)}-- @deprecated: warns callers at check time@deprecated("use new_add() instead")fnold_add(a, b){return a + b }
Test functions produce no visible output when called directly. Run xs test to discover and execute them.