Language Reference
Compact lookup for syntax and built-ins. For explanations, use Getting Started.
Statements
echo
name: str = "Echo";
const count: int = 0;
name = "Echo 2";
[a: int, b: int] = pair;
{ id: int, name: str } = user;
{ id as userId: int } = user;
{ id: int, rest: dynamic... } = user;
if cond { ... }
switch x { 0 { ... } else { ... } }
while cond { ... }
for i: int in 0..10 { ... }
foreach item: str in items { ... }
fn greet(name: str) { ... }
fn lock(const xs: list) { ... }
class Point {
new {
x: int = 0;
y: int = 0;
}
fn origin() -> Point {
return Point {};
}
fn length(this) -> int {
return this.x * this.x + this.y * this.y;
}
}
interface Named {
fn name(this) -> str;
}
class User implements Named {
new { label: str; }
fn name(this) -> str {
return this.label;
}
}
p: Point = Point.origin();
say(p.length());
say(Point.length(Point { x: 3, y: 4 }));
return;
break;
continue;
use name;
use mut count;
watch count;Built-in Types
int,float,str,bool,dynamic,list,hashvoid— function return annotations only- Unions:
int | str(nonulltype member; preferstr | void) - Object shapes:
{ id: int }(open) andexact { id: int }(closed) - Nominal classes:
class Point { new { x: int = 0; y: int; } }(constructionPoint { y: 4 }; unbound methodsPoint.length(p)) - Interfaces:
interface Named { fn name(this) -> str; }(optionalclass User implements Named) - Function types:
fn(int) -> int
Literals
- Integers:
123; floats:12.34,.5, scientific form - Strings:
"hello",'hello', multiline"""/''' - Booleans:
true,false; null:null - Lists:
[1, 2, 3]; hashes:{ key: value } - Ranges as values:
0...10,0..10, optionalby
Operators
- Arithmetic:
+ - * / % - Comparison:
== != < > <= >= - Logical:
&& || ! - Assignment:
=and+= -= *= /= %=
Function Forms
echo
fn name(a: int) { ... }
fn name(a: int) -> int { ... }
fn square(x: int) => x * x;
fn square(x: int) -> int => x * x;
fn add(a: int, b: int = 0) -> int { return a + b; }
fn sum(parts: int...) -> int { ... }Named functions and lambdas are values. Standalone builtins (say, map, …) and bound methods (xs.map) are values too (0.7.3). If a function contains return, it must declare a return type.
Notes
Quick lookup only. Semantics contract: language-semantics.md. Guides live under Getting Started and Examples.
