Quick Reference
ShowThe Stack
Quadrate is stack-based. Values are pushed onto a stack, and operations consume values from the stack.
5 3 +
push 5, push 3, add them → 8
10 print nl
push 10, print it, newline
Variables
Use -> to store a value in a variable, then use the variable name to push it back.
42 -> x
store 42 in x
x x *
push x twice, multiply → 1764
Stack Operations
dup
duplicate top: [a] → [a a]
swap
swap top two: [a b] → [b a]
drop
discard top: [a b] → [a]
over
copy second: [a b] → [a b a]
Math & Comparison
+ - * / %
arithmetic operators
== < > <= >= !=
comparisons → true/false
Control Flow
condition if { ... }
run block if true
if { ... } else { ... }
if-else branch
0 10 1 for i { i print }
loop i from 0 to 9
Functions
Define with inputs and outputs separated by --
fn add(a:i64 b:i64 -- sum:i64)
takes 2 ints, returns 1
fn greet(--) { "Hi" print }
no inputs, no outputs
Strings
"Hello" print
print a string
"Hello" len
string length → 5
"a" "b" str::concat
concatenate → "ab"
Output
print
print top of stack
nl
print newline
. (dot)
print with newline
" " print
print space separator
More Loops
while { cond } { body }
loop while condition true
loop { ... break }
infinite loop, use break
continue
skip to next iteration
Types
i64
integer (64-bit)
f64
floating point
str
string
bool
true or false
Comments
// single line comment
ignored by compiler
/* multi-line */
block comment
Common Patterns
dup *
square a number
2 % 0 ==
check if even
0 > if { ... }
if positive
swap drop
keep second, discard first
Code