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" str::len
string length → 5 (use str)
"a" "b" str::concat
concatenate → "ab"
Output
print
print top of stack
nl
print newline
" " print
print space separator
More Loops
cond while { body; cond }
body must re-push condition
loop { ... break }
infinite loop, use break
continue
skip to next iteration
Types
i64
integer (64-bit)
f64
floating point
str
string
ptr
pointer / array
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
discard second (same as nip)
Code