A 15-Minute Tour of Wysna
Fast hands-on tour of Wysna v0.7 / v0.8 — bindings, ergonomics, structs, pattern matching, contracts, typed errors, generics, async/await, and native builds.
This tour walks through the core idioms of Wysna using real syntax supported across both Seed (v0.9.5) and the Self-Hosted Native SDK (v0.9.5).
1. Bindings, Literals & Interpolation
Section titled “1. Bindings, Literals & Interpolation”Variables are immutable by default (let). Use let mut only when mutation is required. Wysna v0.8 adds hex/binary literals (0x/0b), multiline triple-quoted strings ("""..."""), f-string interpolation (f"..."), and compound assignments (+=, -=, *=).
fn main() -> unit { let flags = 0xFF let mask = 0b1010_0101 let mut counter = 10 counter += 5
let report = f""" === Status === flags={flags}, mask={mask}, counter={counter} """ print(report)}2. Tuples, Collections & Membership
Section titled “2. Tuples, Collections & Membership”Collections (list[T], dict[K, V]) support bidirectional type inference for empty literals ([], {}), .contains(), .is_empty(), x in collection, tuple destructuring, and for k, v in dict:
fn stats(values: list[int]) -> (int, int) { let mut sum = 0 for v in values { sum += v } return (len(values), sum)}
fn main() -> unit { let (count, total) = stats([10, 20, 30]) print(f"count={count}, total={total}")
let ports: dict[str, int] = { "http": 80, "https": 443 } if "https" in ports { for name, port in ports { print(f"{name} -> {port}") } }}3. Structs, Copy-on-Write & Update Syntax
Section titled “3. Structs, Copy-on-Write & Update Syntax”Structs obey pure value semantics. Mutating a copy never leaks into the original binding, and Struct { field: val, ..base } creates an updated value while evaluating base once:
struct Config { host: str port: int tls: bool}
fn main() -> unit { let prod = Config { host: "api.wysofia.com", port: 443, tls: true } let local = Config { host: "127.0.0.1", port: 8080, ..prod }
print(f"prod={prod.host}:{prod.port}") print(f"local={local.host}:{local.port}, tls={local.tls}")}4. Enums & Exhaustive Pattern Matching
Section titled “4. Enums & Exhaustive Pattern Matching”Tagged unions (enum) pair with compile-time exhaustive match. Use _ => for a wildcard fallback arm:
enum Command { Build(str) Test(int) Clean}
fn describe(cmd: Command) -> str { return match cmd { Command.Build(profile) => f"building with profile={profile}" Command.Test(limit) => f"running up to {limit} tests" _ => "cleaning build cache" }}5. Contracts (requires / ensures) & Typed Errors (T ! E)
Section titled “5. Contracts (requires / ensures) & Typed Errors (T ! E)”See contracts in Wysna for the distinction between a contract violation and a recoverable error.
Wysna eliminates unchecked exceptions. Functions declare failure in their signature (T ! E), propagate with ?, recover inline with else err, and enforce contracts ([W4005]):
pub fn quote_total(quantity: int, unit_price_cents: int) -> int ! str requires quantity > 0, unit_price_cents >= 0 ensures result == quantity * unit_price_cents{ if quantity > 10000 { return Err("Order exceeds automated quote threshold") } return quantity * unit_price_cents}
fn main() -> unit { let cents = quote_total(4, 1299) else err { print(f"Error: {err}") 0 } print(f"Total cents: {cents}")}6. Generics, Interfaces & Selective Imports
Section titled “6. Generics, Interfaces & Selective Imports”Import only what you need using from ... use { ... } and express polymorphic contracts with constrained generics ([T: Show]):
from std.text use { to_upper, trim }
interface Show { fn show() -> str}
class Tag[T: Show] { label: str item: T
fn init(label: str, item: T) -> unit { self.label = to_upper(trim(label)) self.item = item }
pub fn format() -> str { return f"[{self.label}] {self.item.show()}" }}7. Stackless CPS async fn & Multi-Core Parallelism
Section titled “7. Stackless CPS async fn & Multi-Core Parallelism”Write cooperative async fn / await coroutines or dispatch CPU-bound work across OS threads with strict index ordering:
from std.algorithms use { parallel_map }
async fn compute_factor() -> int { return 3}
async fn main() -> unit { let factor = await compute_factor() let doubled = parallel_map([1, 2, 3, 4], fn(x: int) -> int { return x * factor }) print(doubled)}8. Check, Impact-Trace & Compile
Section titled “8. Check, Impact-Trace & Compile”# Typecheck and verify contractswysna check app.wysna
# Auto-fix mechanical errors (let -> let mut, typos, str wrapping)wysna fix --apply app.wysna
# Inspect project-wide impact of changing a symbolwysna graph --manifest wysna.toml --symbol quote_total --rel impact
# Build an optimized native binary via ANSI C99wysna build app.wysna -o app --profile release./appReady to go deeper? Continue with Projects & wysna.toml, Generics & Bounds, or the 20-Module Standard Library.