9cf0e3e81c
Eleven binary builtins (+ - * / % == != < <= > >=) render as lhs op rhs when called with two args (tail-flagged keeps prefix). Standard Rust-aligned 4-level precedence table elides parens. not(x) renders as !x. Long /// doc strings wrap at 80 cols on word boundaries. bench_list_sum: 'if ==(n, 0)' becomes 'if n == 0', '+(acc, h)' becomes 'acc + h', tail keyword still visible on tail calls. 19 new unit tests (47 total). 4 snapshots (3 re-rendered + 1 new bench fixture). Public API unchanged.
22 lines
669 B
Plaintext
22 lines
669 B
Plaintext
// module rc_own_param_drop
|
|
|
|
/// Recursive Int list — boxed.
|
|
data IntList = Nil | Cons(Int, IntList)
|
|
|
|
/// Take ownership of an IntList; return its head if Cons, else 0. The tail is
|
|
/// loaded as a pattern binder but never consumed — iter A dec's it at arm
|
|
/// close. The outer cell is dec'd at fn return via iter B's Own-param emission.
|
|
fn head_or_zero(xs: own IntList) -> Int {
|
|
match xs {
|
|
Nil => 0,
|
|
Cons(h, t) => h
|
|
}
|
|
}
|
|
|
|
/// Build a 5-element IntList; pass to head_or_zero (transferring ownership);
|
|
/// print the result.
|
|
fn main() -> Unit with IO {
|
|
let xs = Cons(11, Cons(22, Cons(33, Cons(44, Cons(55, Nil)))));
|
|
do io/print_int(head_or_zero(xs))
|
|
}
|