|
| 1 | +// ============================================================================== |
| 2 | +// AETHER Language Showcase: Functional Pipelines, Comptime, Async/Await & Task, |
| 3 | +// Context Managers & LIFO Defer, Native Regex, Diagnostics, Formatter & Linter |
| 4 | +// ============================================================================== |
| 5 | + |
| 6 | +print("=== 1. Functional Collection Pipeline Methods ===") |
| 7 | +let raw_scores = [45, 92, 78, 92, 60, 88, 100, 45] |
| 8 | +let top_bonus_total = raw_scores.unique().sort().filter(|s| s >= 80).map(|s| s + 5).reduce(0, |acc, s| acc + s) |
| 9 | +print("Top bonus total:", top_bonus_total) |
| 10 | + |
| 11 | +print("\n=== 2. Compile-Time Execution (comptime) & Macros ===") |
| 12 | +macro cube(n) { |
| 13 | + n * n * n |
| 14 | +} |
| 15 | +let FIB_TABLE = comptime { |
| 16 | + let mut seq = [0, 1] |
| 17 | + for i in 2..=8 { |
| 18 | + seq.push(seq[i - 1] + seq[i - 2]) |
| 19 | + } |
| 20 | + seq |
| 21 | +} |
| 22 | +print("Precomputed FIB_TABLE at compile time:", FIB_TABLE) |
| 23 | +print("macro cube(4):", cube(4)) |
| 24 | + |
| 25 | +print("\n=== 3. Async / Await & Structured Task Concurrency ===") |
| 26 | +async fn compute_metric(n) { |
| 27 | + return n * n + 10 |
| 28 | +} |
| 29 | +let t1 = Task.spawn(compute_metric, 6) |
| 30 | +let t2 = Task.spawn(compute_metric, 9) |
| 31 | +let results = Task.all([t1, t2]) |
| 32 | +print("Task.all results:", results) |
| 33 | + |
| 34 | +print("\n=== 4. Deterministic Resource Management (with ... as ... & LIFO defer) ===") |
| 35 | +let events = [] |
| 36 | +class Session { |
| 37 | + fn __init__(self, id) { |
| 38 | + self.id = id |
| 39 | + } |
| 40 | + fn __enter__(self) { |
| 41 | + events.push("open:" + self.id) |
| 42 | + return self |
| 43 | + } |
| 44 | + fn __exit__(self) { |
| 45 | + events.push("close:" + self.id) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +fn process_request() { |
| 50 | + defer events.push("cleanup:outer") |
| 51 | + defer events.push("cleanup:inner") |
| 52 | + with Session("sess-01") as s { |
| 53 | + events.push("query:" + s.id) |
| 54 | + } |
| 55 | + return "done" |
| 56 | +} |
| 57 | +let _ = process_request() |
| 58 | +print("Lifecycle trace:", events.join(" -> ")) |
| 59 | + |
| 60 | +print("\n=== 5. Native Zero-Dependency Regex Engine ===") |
| 61 | +let log_line = "2026-10-23 [ERROR] User #4091 failed login from 10.0.0.12" |
| 62 | +print("Regex is_match:", Regex.is_match("^2026-[0-9]{2}-[0-9]{2}", log_line)) |
| 63 | +print("Regex find:", Regex.find("#[0-9]+", log_line)) |
| 64 | +print("Regex replace_all:", Regex.replace_all("[0-9]+", log_line, "X")) |
| 65 | + |
| 66 | +print("\n=== 6. Built-in Code Formatter, Linter & Fuzzy Diagnostics ===") |
| 67 | +let sample_code = "fn demo(a){\nlet unused_var = 42\nreturn a+1\n}\n" |
| 68 | +print("Linter warnings:", Linter.lint(sample_code)) |
| 69 | +print("Fuzzy suggestion for 'prnt':", Diagnostics.suggest("prnt", ["print", "println", "len"])) |
0 commit comments