aboutsummaryrefslogtreecommitdiff
path: root/examples/learn
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-14 08:29:46 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-14 08:29:46 +0330
commit1c53304d03414890af0da7432d1aea87e754a14a (patch)
tree97190d86cf548c9bc63f68c86a4d2a4f09809713 /examples/learn
parenta (diff)
feat: grow memory limits, add icon/actor libraries, overhaul LSP diagnostics
Compiler and VM - make every memory map limit dynamic and adjustable at both build time and runtime, including compiler tables, stacks, and every execution region - reserve and grow tables, operand and return stacks, frame segments, and image-building output without relocating live code or globals - rename i/o and string helpers consistently (puts -> put_s, putn -> put_n, scat -> cat_s) across compiler, runtime, examples, tests, and docs - recast and consume values assigned to globals from inside functions - allow fixed and const together, add typed closure returns (fn:t(...)), multi-include syntax (include rt, run, core;), and recurse type inference - never infer string literals as word, anywhere, as argument, variable, or return type - draft docs/BORROW.md: a borrow checker less intrusive than Rust's but more intelligent LSP and editor integration - require explicit includes and give every toolchain area its own namespace (rt, lsp, run, core) - hover for built-in types, inferred types, values known at hover time, array and pointer lifetime/size, library names in include statements, and inferred lifetimes with explanations - honor /* */ comments as documentation for variables and arguments, and stop misattributing section headers or trailing comments as variable hints - stream diagnostics and cancel stale requests on change - jump to definition and references, including cross-file - quick fixes with automatic library import, and namespace completion Hints and diagnostics - render hints as blue squigglies by default, with hints on/small/off per file - suppress magic-number hints via a preceding /* */ comment, and say so - warn on unused arguments; allow multiple _ discards in parameters, pattern matching, and tagged enums, warning if a _ is actually used - rewrite hint and comment prose in professional compiler-doc register Libraries - add icon.zc: run-time self-modification, find/replace syntax, type and block edits, and step-through inspection of locals and globals - add actor.zc: async actors with Actor<I,O>, implicit this, spawn/recv/send, injected into the compiler machinery at include time rather than built in Tooling and docs - reorganize sources, tests, and designs into subdirectories - unify windows entry points in tinyvm.bat and add a matching tinyvm.sh - add --help across the toolchain - polish the learning guide, stdlib docs, and design notes Tests - add accept, reject, and regression coverage across the compiler, LSP, - runtime, icon, actors, threads, formatting, and the toolchain contracts, plus fuzzers and property tests
Diffstat (limited to 'examples/learn')
-rw-r--r--examples/learn/01-hello.zc5
-rw-r--r--examples/learn/02-loops.zc5
-rw-r--r--examples/learn/03-do-continue.zc5
-rw-r--r--examples/learn/04-enums.zc5
-rw-r--r--examples/learn/05-small-ints.zc11
-rw-r--r--examples/learn/06-floats.zc7
-rw-r--r--examples/learn/07-bytes.zc9
-rw-r--r--examples/learn/08-byte-strings.zc9
-rw-r--r--examples/learn/09-shared.zc13
-rw-r--r--examples/learn/10-owned.zc7
-rw-r--r--examples/learn/11-tags.zc7
-rw-r--r--examples/learn/12-aliases.zc7
-rw-r--r--examples/learn/13-memdebug.out2
-rw-r--r--examples/learn/13-memdebug.zc9
-rw-r--r--examples/learn/14-include.zc10
-rw-r--r--examples/learn/15-generics.zc7
-rw-r--r--examples/learn/16-tagged-enums.zc11
-rw-r--r--examples/learn/17-switch.zc7
-rw-r--r--examples/learn/18-o3.zc11
-rw-r--r--examples/learn/19-growable.out4
-rw-r--r--examples/learn/19-growable.zc17
-rw-r--r--examples/learn/20-text-num.zc8
-rw-r--r--examples/learn/21-host.zc6
-rw-r--r--examples/learn/22-raw-x86.zc6
-rw-r--r--examples/learn/23-c-abi.zc9
-rw-r--r--examples/learn/24-backtick.zc5
-rw-r--r--examples/learn/25-closures.zc7
-rw-r--r--examples/learn/26-closure-state.out2
-rw-r--r--examples/learn/26-closure-state.zc9
-rw-r--r--examples/learn/27-namespaces.out1
-rw-r--r--examples/learn/27-namespaces.zc7
-rw-r--r--examples/learn/28-string-inference.out1
-rw-r--r--examples/learn/28-string-inference.zc8
-rw-r--r--examples/learn/29-block-comments.out1
-rw-r--r--examples/learn/29-block-comments.zc11
-rw-r--r--examples/learn/30-typed-closure.out1
-rw-r--r--examples/learn/30-typed-closure.zc12
-rw-r--r--examples/learn/31-array-algorithms.out1
-rw-r--r--examples/learn/31-array-algorithms.zc11
-rw-r--r--examples/learn/32-inferred-calls.out1
-rw-r--r--examples/learn/32-inferred-calls.zc25
-rw-r--r--examples/learn/33-const-fixed.out1
-rw-r--r--examples/learn/33-const-fixed.zc14
43 files changed, 219 insertions, 96 deletions
diff --git a/examples/learn/01-hello.zc b/examples/learn/01-hello.zc
index 10cf4bf..c102c6c 100644
--- a/examples/learn/01-hello.zc
+++ b/examples/learn/01-hello.zc
@@ -1,4 +1,5 @@
+namespace;
+include rt;
fn main() {
- put_s("hello, world!\n");
- return 0;
+ rt.put_s("hello, world!\n");
}
diff --git a/examples/learn/02-loops.zc b/examples/learn/02-loops.zc
index 832e32f..66d7ea7 100644
--- a/examples/learn/02-loops.zc
+++ b/examples/learn/02-loops.zc
@@ -1,6 +1,7 @@
+namespace;
+include rt;
fn main() {
let i = 0, n = 0;
while (i < 4) { n = n + i; i++; }
- put_n(n); put_c(10);
- return 0;
+ rt.put_n(n); rt.put_c(10);
}
diff --git a/examples/learn/03-do-continue.zc b/examples/learn/03-do-continue.zc
index 70959f4..74aa29c 100644
--- a/examples/learn/03-do-continue.zc
+++ b/examples/learn/03-do-continue.zc
@@ -1,6 +1,7 @@
+namespace;
+include rt;
fn main() {
int n = 0, i = 0;
do { i++; if (i == 2) continue; n = n + i; } while (i < 5);
- put_n(n); put_c(10);
- return 0;
+ rt.put_n(n); rt.put_c(10);
}
diff --git a/examples/learn/04-enums.zc b/examples/learn/04-enums.zc
index 8f80e3c..8b3c0dc 100644
--- a/examples/learn/04-enums.zc
+++ b/examples/learn/04-enums.zc
@@ -1,5 +1,6 @@
+namespace;
+include rt;
enum color { RED, GREEN = 5, BLUE };
fn main() {
- put_n(RED); put_c(32); put_n(GREEN); put_c(32); put_n(BLUE); put_c(10);
- return 0;
+ rt.put_n(RED); rt.put_c(32); rt.put_n(GREEN); rt.put_c(32); rt.put_n(BLUE); rt.put_c(10);
}
diff --git a/examples/learn/05-small-ints.zc b/examples/learn/05-small-ints.zc
index b288181..85555ce 100644
--- a/examples/learn/05-small-ints.zc
+++ b/examples/learn/05-small-ints.zc
@@ -1,9 +1,10 @@
+namespace;
+include rt;
fn main() {
u8 a = 250; a = a + 10;
- put_n(a); put_c(10);
- put_n(sizeof([100]u8)); put_c(10);
- u8* px = new(u8, 4096);
+ rt.put_n(a); rt.put_c(10);
+ rt.put_n(sizeof(u8[100])); rt.put_c(10);
+ u8* px = rt.new(u8, 4096);
px[10] = 300;
- put_n(px[10]); put_c(10);
- return 0;
+ rt.put_n(px[10]); rt.put_c(10);
}
diff --git a/examples/learn/06-floats.zc b/examples/learn/06-floats.zc
index 06d23fa..bc0f4b3 100644
--- a/examples/learn/06-floats.zc
+++ b/examples/learn/06-floats.zc
@@ -1,6 +1,7 @@
-fn put_f(x) { asm { x @ #1220 } return 0; }
+namespace;
+include rt;
+void put_f(float x) { asm { x @ #1220 } }
fn main() {
let a = 1.5;
- put_f(a + 2.5); put_c(10);
- return 0;
+ put_f(a + 2.5); rt.put_c(10);
}
diff --git a/examples/learn/07-bytes.zc b/examples/learn/07-bytes.zc
index 7d06282..cf07db6 100644
--- a/examples/learn/07-bytes.zc
+++ b/examples/learn/07-bytes.zc
@@ -1,7 +1,8 @@
+namespace;
+include rt;
fn main() {
let w = 0;
- st8(addr_b(&w), 0x11);
- st8(addr_b(&w) + 1, 0x22);
- put_n(ld8(addr_b(&w))); put_c(32); put_n(w); put_c(10);
- return 0;
+ rt.st8(rt.addr_b(&w), 0x11);
+ rt.st8(rt.addr_b(&w) + 1, 0x22);
+ rt.put_n(rt.ld8(rt.addr_b(&w))); rt.put_c(32); rt.put_n(w); rt.put_c(10);
}
diff --git a/examples/learn/08-byte-strings.zc b/examples/learn/08-byte-strings.zc
index 0959ceb..fb7a8d9 100644
--- a/examples/learn/08-byte-strings.zc
+++ b/examples/learn/08-byte-strings.zc
@@ -1,8 +1,9 @@
+namespace;
+include rt;
fn main() {
let name = b"zc";
let hi = b"hello, " + name;
- put_s(hi); put_c(10);
- put_n(len(hi)); put_c(32);
- put_n(s_to_n(b"40") + 2); put_c(10);
- return 0;
+ rt.put_s(hi); rt.put_c(10);
+ rt.put_n(len(hi)); rt.put_c(32);
+ rt.put_n(rt.s_to_n(b"40") + 2); rt.put_c(10);
}
diff --git a/examples/learn/09-shared.zc b/examples/learn/09-shared.zc
index ab3ca06..db5c407 100644
--- a/examples/learn/09-shared.zc
+++ b/examples/learn/09-shared.zc
@@ -1,8 +1,9 @@
+namespace;
+include rt;
fn main() {
- let tail = cons(1, 2);
- let left = cons(tail, 3);
- let right = cons(tail, 4);
- put_n(car(car(left))); put_c(32);
- put_n(car(left) == car(right)); put_c(10);
- return 0;
+ let tail = rt.cons(1, 2);
+ let left = rt.cons(tail, 3);
+ let right = rt.cons(tail, 4);
+ rt.put_n(rt.car(rt.car(left))); rt.put_c(32);
+ rt.put_n(rt.car(left) == rt.car(right)); rt.put_c(10);
}
diff --git a/examples/learn/10-owned.zc b/examples/learn/10-owned.zc
index 3aff9a4..2ee84c0 100644
--- a/examples/learn/10-owned.zc
+++ b/examples/learn/10-owned.zc
@@ -1,6 +1,7 @@
+namespace;
+include rt;
fn main() {
- int* p = new(int);
+ int* p = rt.new(int);
*p = 7;
- put_n(*p); put_c(10);
- return 0;
+ rt.put_n(*p); rt.put_c(10);
}
diff --git a/examples/learn/11-tags.zc b/examples/learn/11-tags.zc
index 08edb58..7e9f6c9 100644
--- a/examples/learn/11-tags.zc
+++ b/examples/learn/11-tags.zc
@@ -1,6 +1,7 @@
-int*.u box(int v) { int* b = new(int); *b = v; return u*b; }
+namespace;
+include rt;
+int*.u box(int v) { int* b = rt.new(int); *b = v; return b; }
fn main() {
int* p = box(4);
- put_n(*p); put_c(10);
- return 0;
+ rt.put_n(*p); rt.put_c(10);
}
diff --git a/examples/learn/12-aliases.zc b/examples/learn/12-aliases.zc
index abb39d5..341738d 100644
--- a/examples/learn/12-aliases.zc
+++ b/examples/learn/12-aliases.zc
@@ -1,8 +1,9 @@
+namespace;
+include rt;
struct node { int v; node* next; };
fn main() {
- node* a = new(node), b = new(node);
+ node* a = rt.new(node), b = rt.new(node);
a.v = 3; b.v = 4; a.next = b;
node* c = a.next;
- put_n(c.v); put_c(10);
- return 0;
+ rt.put_n(c.v); rt.put_c(10);
}
diff --git a/examples/learn/13-memdebug.out b/examples/learn/13-memdebug.out
index c168a7b..f788938 100644
--- a/examples/learn/13-memdebug.out
+++ b/examples/learn/13-memdebug.out
@@ -1,2 +1,2 @@
-leak: line 4 3 words
+leak: line 6 3 words
1
diff --git a/examples/learn/13-memdebug.zc b/examples/learn/13-memdebug.zc
index 80ee0da..fd646a5 100644
--- a/examples/learn/13-memdebug.zc
+++ b/examples/learn/13-memdebug.zc
@@ -1,10 +1,11 @@
+namespace;
+include rt;
memdebug on;
int* g;
fn main() {
- int* p = new(int);
+ int* p = rt.new(int);
*p = 1;
g = d*p;
- put_n(memreport());
- put_c(10);
- return 0;
+ rt.put_n(rt.memreport());
+ rt.put_c(10);
}
diff --git a/examples/learn/14-include.zc b/examples/learn/14-include.zc
index c126389..f3be88c 100644
--- a/examples/learn/14-include.zc
+++ b/examples/learn/14-include.zc
@@ -1,7 +1,7 @@
-include "src/lib/std.zc";
+namespace;
+include rt, std;
fn main() {
- let s = readfile("tests/data/hi.txt");
- put_n(len_w(s)); put_c(10);
- free(d*s);
- return 0;
+ let s = rt.readfile("tests/data/hi.txt");
+ rt.put_n(rt.len_w(s)); rt.put_c(10);
+ rt.free(s);
}
diff --git a/examples/learn/15-generics.zc b/examples/learn/15-generics.zc
index dfc4833..2da24e5 100644
--- a/examples/learn/15-generics.zc
+++ b/examples/learn/15-generics.zc
@@ -1,9 +1,10 @@
+namespace;
+include rt;
struct record<K, V> { K key; V val; };
struct point { int x; int y; };
K keyof<K, V>(record<K, V>* r) { return r.key; }
fn main() {
- record<int, point>* r = new(record<int, point>);
+ record<int, point>* r = rt.new(record<int, point>);
r.key = 9;
- put_n(keyof(r)); put_c(10);
- return 0;
+ rt.put_n(keyof(r)); rt.put_c(10);
}
diff --git a/examples/learn/16-tagged-enums.zc b/examples/learn/16-tagged-enums.zc
index ba430f4..27d23c3 100644
--- a/examples/learn/16-tagged-enums.zc
+++ b/examples/learn/16-tagged-enums.zc
@@ -1,3 +1,5 @@
+namespace;
+include rt;
enum shape { circle { int r; }, rect { int w; int h; }, dot };
int area(shape* s) {
switch (s) {
@@ -9,10 +11,9 @@ int area(shape* s) {
}
fn main() {
shape* s = shape.circle(3);
- put_n(area(s)); put_c(10);
- free(d*s);
+ rt.put_n(area(s)); rt.put_c(10);
+ rt.free(s);
shape* t = shape.rect(2, 5);
- put_n(area(t)); put_c(10);
- free(d*t);
- return 0;
+ rt.put_n(area(t)); rt.put_c(10);
+ rt.free(t);
}
diff --git a/examples/learn/17-switch.zc b/examples/learn/17-switch.zc
index f03aba9..06d5bb0 100644
--- a/examples/learn/17-switch.zc
+++ b/examples/learn/17-switch.zc
@@ -1,6 +1,7 @@
+namespace;
+include rt;
fn main() {
int k = 2;
- switch (k) { case 1: put_s("one"); break; case 2: put_s("two"); break; default: put_s("other"); }
- put_c(10);
- return 0;
+ switch (k) { case 1: rt.put_s("one"); break; case 2: rt.put_s("two"); break; default: rt.put_s("other"); }
+ rt.put_c(10);
}
diff --git a/examples/learn/18-o3.zc b/examples/learn/18-o3.zc
index cb2237a..9e591ed 100644
--- a/examples/learn/18-o3.zc
+++ b/examples/learn/18-o3.zc
@@ -1,10 +1,11 @@
-o3 int sum(fixed []int a) { int s = 0; for (int i = 0; i < len(a); i++) s += a[i]; return s; }
+namespace;
+include rt;
+o3 int sum(fixed int[?] a) { int s = 0; for (int i = 0; i < len(a); i++) s += a[i]; return s; }
fn main() {
- fixed []int a = new(fixed []int, 5);
+ fixed int[?] a = rt.new(fixed int[?], 5);
for (int i = 0; i < 5; i++) a[i] = i * i;
- put_n(sum(a)); put_c(10);
+ rt.put_n(sum(a)); rt.put_c(10);
o3 int hits = 0;
o3 { for (int i = 0; i < 1000; i++) if (i % 7 == 3) hits++; }
- put_n(hits); put_c(10);
- return 0;
+ rt.put_n(hits); rt.put_c(10);
}
diff --git a/examples/learn/19-growable.out b/examples/learn/19-growable.out
index 4a9aeea..2b836a1 100644
--- a/examples/learn/19-growable.out
+++ b/examples/learn/19-growable.out
@@ -1,3 +1,5 @@
-2
+2 4
5
+4
+3 3
3
diff --git a/examples/learn/19-growable.zc b/examples/learn/19-growable.zc
index e5ed8de..39a484c 100644
--- a/examples/learn/19-growable.zc
+++ b/examples/learn/19-growable.zc
@@ -1,13 +1,18 @@
+namespace;
+include rt;
struct cnt {
int n;
static int make() { return 3; }
int get() { return this.n; }
};
fn main() {
- []int xs = new([]int);
- push(xs, 4); push(xs, 5);
- put_n(len(xs)); put_c(10);
- put_n(pop(xs)); put_c(10);
- put_n(cnt.make()); put_c(10);
- return 0;
+ int[?] xs = rt.new(int[?]);
+ xs.push(4); xs.push(5);
+ rt.put_n(xs.len()); rt.put_c(32); rt.put_n(xs.cap()); rt.put_c(10);
+ rt.put_n(xs.pop()); rt.put_c(10);
+ xs.resize(4);
+ rt.put_n(xs.len()); rt.put_c(10);
+ int[3] fixed = {1, 2, 3};
+ rt.put_n(fixed.len()); rt.put_c(32); rt.put_n(fixed.cap()); rt.put_c(10);
+ rt.put_n(cnt.make()); rt.put_c(10);
}
diff --git a/examples/learn/20-text-num.zc b/examples/learn/20-text-num.zc
index 027b721..2d2a118 100644
--- a/examples/learn/20-text-num.zc
+++ b/examples/learn/20-text-num.zc
@@ -1,6 +1,6 @@
-include "src/lib/std.zc";
+namespace;
+include rt, std;
fn main() {
- put_n(Num.gcd(12, 18)); put_c(32); put_n(Num.pow(2, 10)); put_c(32); put_n(Num.isqrt(50)); put_c(10);
- put_n(Text.atoi("123") + 1); put_c(10);
- return 0;
+ rt.put_n(std.Num.gcd(12, 18)); rt.put_c(32); rt.put_n(std.Num.pow(2, 10)); rt.put_c(32); rt.put_n(std.Num.isqrt(50)); rt.put_c(10);
+ rt.put_n(std.Text.atoi("123") + 1); rt.put_c(10);
}
diff --git a/examples/learn/21-host.zc b/examples/learn/21-host.zc
index 550e747..ca77c41 100644
--- a/examples/learn/21-host.zc
+++ b/examples/learn/21-host.zc
@@ -1,5 +1,5 @@
-include "src/lib/std.zc";
+namespace;
+include rt, std;
fn main() {
- put_n(Host.now() > 0); put_c(10);
- return 0;
+ rt.put_n(std.Host.now() > 0); rt.put_c(10);
}
diff --git a/examples/learn/22-raw-x86.zc b/examples/learn/22-raw-x86.zc
index e274aee..67c532a 100644
--- a/examples/learn/22-raw-x86.zc
+++ b/examples/learn/22-raw-x86.zc
@@ -1,5 +1,5 @@
-include "src/lib/std.zc";
+namespace;
+include rt, std;
fn main() {
- put_n(Host.raw(39, 0, 0, 0, 0, 0, 0) > 0); put_c(10);
- return 0;
+ rt.put_n(std.Host.raw(39, 0, 0, 0, 0, 0, 0) > 0); rt.put_c(10);
}
diff --git a/examples/learn/23-c-abi.zc b/examples/learn/23-c-abi.zc
index 3df4b75..134e926 100644
--- a/examples/learn/23-c-abi.zc
+++ b/examples/learn/23-c-abi.zc
@@ -1,12 +1,13 @@
-fn put_f(x) { asm { x @ #1220 } return 0; }
+namespace;
+include rt;
+void put_f(float x) { asm { x @ #1220 } }
extern double sqrt(double);
extern void qsort(word *base, long n, long size, void *cmp);
int cmp(int* a, int* b) { return *a - *b; }
fn main() {
let a[4];
a[0] = 5; a[1] = 3; a[2] = 9; a[3] = 1;
- put_f(sqrt(2.0)); put_c(10);
+ put_f(sqrt(2.0)); rt.put_c(10);
qsort(a, 4, 8, cfunc(cmp));
- put_n(a[0]); put_c(32); put_n(a[1]); put_c(32); put_n(a[2]); put_c(32); put_n(a[3]); put_c(10);
- return 0;
+ rt.put_n(a[0]); rt.put_c(32); rt.put_n(a[1]); rt.put_c(32); rt.put_n(a[2]); rt.put_c(32); rt.put_n(a[3]); rt.put_c(10);
}
diff --git a/examples/learn/24-backtick.zc b/examples/learn/24-backtick.zc
index 0317631..d9e014d 100644
--- a/examples/learn/24-backtick.zc
+++ b/examples/learn/24-backtick.zc
@@ -1,5 +1,6 @@
+namespace;
+include rt;
fn main() {
- put_c(get_c()); put_c(get_c()); put_c(10);
- return 0;
+ rt.put_c(rt.get_c()); rt.put_c(rt.get_c()); rt.put_c(10);
}
`abc
diff --git a/examples/learn/25-closures.zc b/examples/learn/25-closures.zc
index 72c236d..d7d6dd6 100644
--- a/examples/learn/25-closures.zc
+++ b/examples/learn/25-closures.zc
@@ -1,8 +1,9 @@
+namespace;
+include rt;
fn apply(f, x) { return f(x); }
fn main() {
let k = 10;
let add = fn(x) { return x + k; };
- put_n(add(1)); put_c(10);
- put_n(apply(add, 5)); put_c(10);
- return 0;
+ rt.put_n(add(1)); rt.put_c(10);
+ rt.put_n(apply(add, 5)); rt.put_c(10);
}
diff --git a/examples/learn/26-closure-state.out b/examples/learn/26-closure-state.out
index 33aea5d..1f1b4f4 100644
--- a/examples/learn/26-closure-state.out
+++ b/examples/learn/26-closure-state.out
@@ -1,3 +1,3 @@
109
1 5
-0
+5
diff --git a/examples/learn/26-closure-state.zc b/examples/learn/26-closure-state.zc
index f3ddf50..7d941af 100644
--- a/examples/learn/26-closure-state.zc
+++ b/examples/learn/26-closure-state.zc
@@ -1,13 +1,14 @@
+namespace;
+include rt;
fn main() {
let base = 2;
let outer = fn(x) {
let inner = fn(y) { return y + base + x; };
return inner(100);
};
- put_n(outer(7)); put_c(10);
+ rt.put_n(outer(7)); rt.put_c(10);
let count = 0;
let tick = fn(d) { count = count + d; return count; };
- put_n(tick(1)); put_c(32); put_n(tick(4)); put_c(10);
- put_n(count); put_c(10);
- return 0;
+ rt.put_n(tick(1)); rt.put_c(32); rt.put_n(tick(4)); rt.put_c(10);
+ rt.put_n(count); rt.put_c(10);
}
diff --git a/examples/learn/27-namespaces.out b/examples/learn/27-namespaces.out
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/examples/learn/27-namespaces.out
@@ -0,0 +1 @@
+42
diff --git a/examples/learn/27-namespaces.zc b/examples/learn/27-namespaces.zc
new file mode 100644
index 0000000..2b2bf68
--- /dev/null
+++ b/examples/learn/27-namespaces.zc
@@ -0,0 +1,7 @@
+namespace app;
+include rt, std;
+int twice(int n) { return n * 2; }
+fn main() {
+ let text = "21";
+ rt.put_n(twice(std.Text.atoi(text))); rt.put_c(10);
+}
diff --git a/examples/learn/28-string-inference.out b/examples/learn/28-string-inference.out
new file mode 100644
index 0000000..c8f6b59
--- /dev/null
+++ b/examples/learn/28-string-inference.out
@@ -0,0 +1 @@
+11 12
diff --git a/examples/learn/28-string-inference.zc b/examples/learn/28-string-inference.zc
new file mode 100644
index 0000000..877a003
--- /dev/null
+++ b/examples/learn/28-string-inference.zc
@@ -0,0 +1,8 @@
+namespace;
+include rt, std;
+fn main() {
+ let word_text = "word string";
+ let packed_text = b"packed bytes";
+ rt.put_n(std.Text.len(word_text)); rt.put_c(32);
+ rt.put_n(std.Bytes.len(packed_text)); rt.put_c(10);
+}
diff --git a/examples/learn/29-block-comments.out b/examples/learn/29-block-comments.out
new file mode 100644
index 0000000..120cc7d
--- /dev/null
+++ b/examples/learn/29-block-comments.out
@@ -0,0 +1 @@
+16640
diff --git a/examples/learn/29-block-comments.zc b/examples/learn/29-block-comments.zc
new file mode 100644
index 0000000..a5088eb
--- /dev/null
+++ b/examples/learn/29-block-comments.zc
@@ -0,0 +1,11 @@
+namespace;
+include rt;
+
+/* adds a memory offset to an address. */
+int offset_address(int address) {
+ return address + /* offset in memory */ 0x40ff;
+}
+
+fn main() {
+ rt.put_n(offset_address(1)); rt.put_c(10);
+}
diff --git a/examples/learn/30-typed-closure.out b/examples/learn/30-typed-closure.out
new file mode 100644
index 0000000..d81cc07
--- /dev/null
+++ b/examples/learn/30-typed-closure.out
@@ -0,0 +1 @@
+42
diff --git a/examples/learn/30-typed-closure.zc b/examples/learn/30-typed-closure.zc
new file mode 100644
index 0000000..a2c090d
--- /dev/null
+++ b/examples/learn/30-typed-closure.zc
@@ -0,0 +1,12 @@
+namespace;
+include rt;
+
+word.u multiplier(int factor) {
+ let scale = fn:int(int n) { return n * factor; };
+ return u*scale;
+}
+
+fn main() {
+ let scale = multiplier(3);
+ rt.put_n(scale(14)); rt.put_c(10);
+}
diff --git a/examples/learn/31-array-algorithms.out b/examples/learn/31-array-algorithms.out
new file mode 100644
index 0000000..ec26cf8
--- /dev/null
+++ b/examples/learn/31-array-algorithms.out
@@ -0,0 +1 @@
+2 4 24
diff --git a/examples/learn/31-array-algorithms.zc b/examples/learn/31-array-algorithms.zc
new file mode 100644
index 0000000..d74bc74
--- /dev/null
+++ b/examples/learn/31-array-algorithms.zc
@@ -0,0 +1,11 @@
+namespace;
+include rt, std;
+
+fn main() {
+ int[?] values = {1, 2, 3, 4, 5};
+ let doubled = values.map(fn(e) { return e * 2; });
+ let large = doubled.filter(fn(e) { return e > 4; });
+ rt.put_n(values.find(3)); rt.put_c(32);
+ rt.put_n(values.find_if(fn(e) { return e > 4; })); rt.put_c(32);
+ rt.put_n(large.reduce(0, fn(total, e) { return total + e; })); rt.put_c(10);
+}
diff --git a/examples/learn/32-inferred-calls.out b/examples/learn/32-inferred-calls.out
new file mode 100644
index 0000000..fa9f1d8
--- /dev/null
+++ b/examples/learn/32-inferred-calls.out
@@ -0,0 +1 @@
+41 7
diff --git a/examples/learn/32-inferred-calls.zc b/examples/learn/32-inferred-calls.zc
new file mode 100644
index 0000000..295d007
--- /dev/null
+++ b/examples/learn/32-inferred-calls.zc
@@ -0,0 +1,25 @@
+namespace;
+include rt;
+
+fn layer0(n) { return seed(n); }
+fn layer1(n) { return layer0(n); }
+fn layer2(n) { return layer1(n); }
+int seed(int n) { return n; }
+fn countdown(n) {
+ if (n == 0) return seed(7);
+ return countdown(n - 1);
+}
+.u make_list(cap) {
+ let list = rt.new(cap + 1);
+ list[0] = cap;
+ return list;
+}
+.u pass_list(n) {
+ let list = make_list(n);
+ return list;
+}
+fn main() {
+ let list = pass_list(layer2(41));
+ rt.put_n(list[0]); rt.put_c(32);
+ rt.put_n(countdown(3)); rt.put_c(10);
+}
diff --git a/examples/learn/33-const-fixed.out b/examples/learn/33-const-fixed.out
new file mode 100644
index 0000000..e764420
--- /dev/null
+++ b/examples/learn/33-const-fixed.out
@@ -0,0 +1 @@
+7 2 5 8
diff --git a/examples/learn/33-const-fixed.zc b/examples/learn/33-const-fixed.zc
new file mode 100644
index 0000000..bbc85ec
--- /dev/null
+++ b/examples/learn/33-const-fixed.zc
@@ -0,0 +1,14 @@
+namespace;
+include rt;
+int first(const fixed int[2] values) { return values[0]; }
+fn main() {
+ const fixed int[2] a = {7, 8};
+ fixed const int[2] b = {2, 3};
+ fixed int[2] c = {5, 6};
+ int copy = a[0];
+ copy++;
+ rt.put_n(first(a)); rt.put_c(32);
+ rt.put_n(first(b)); rt.put_c(32);
+ rt.put_n(first(c)); rt.put_c(32);
+ rt.put_n(copy); rt.put_c(10);
+}