Module
std.range — operations over the language's a..b. Stability tier: core.
**Four functions, all O(1), on the two accessors [type.range] gave the type at wolf 0.2.14 (s158, wolf-lang#24; F-0030 CLOSED).** A range[int] is a nameable type with start and end as properties, and end is EXCLUSIVE, always: a..=b normalizes at construction to end = b + 1 under [mem.iter.range]'s checked arithmetic, so (2..=7).end is 8 and r.end - r.start is the count for both spellings ([type.range.accessor]). That one exclusive end is what makes contains, len and clamp_to writable at all. sc04 reviewed their signatures and F-0030 recorded them as unwritable for eleven sprints, because the only spelling was iteration: O(len) for an O(1) question, and a hang rather than an answer on 0..9223372036854775807. is_empty shipped alone, on the one fact iteration can decide in O(1), and is now the same comparison as the other three.
A reversed range is a legal, empty value. 7..3 iterates zero times — [mem.iter.range] steps ascending while < end — so is_empty(7..3) is true, and its raw end - start is -4, measured at wolf 0.2.14 on both rungs. len therefore answers the COUNT of values a for would yield, which is 0 there, and not the signed difference wolf-std#30 spelled: a function named len that answers a negative number is the wrong-on-legal-input shape sc03's refusal-over-approximation rule (§9) does not ship. clamp_to on an empty range has no member to answer with and raises none (§2: absence is a row tag, never a sentinel), a row the reviewed signature did not carry; returning start — a number the range does not contain — would be the same wrong answer under a different name.
Lane words, named. Both compiler rungs run every row here at 0.2.14. The reference machine (lupin 0.1.36) conforms to a7f517e = v0.2.12 and has not mirrored [type.range.accessor]: r.start and r.end are declined BY NAME at resolve there — "a range has no member start", F-0030's sentence, a whole-program unsupported and never a diagnostic — so every test in tests/range/ is unsupported on lupin, is_empty's included (it ran there while its body was a loop). The examples below are FENCED, under the extractor's mirror-lag word (LUPIN_MIRROR_LAG, wolf-std#37, sc49): both compiler rungs must run each block to exit(0), and the reference lane must decline it with exactly that sentence. They were prose at sc48 because doc-examples accepted a lupin unsupported only for capability modules, and a fence would have been a red. The release that mirrors the clause reds the five lupin test rows (deeper than the ledger) AND these four blocks on the same day, and the entry leaves in the commit that flips them.
**A fifth function, collect, is [type.comb.set]'s** (sc50, wolf-lang 4c046f15): the one combinator whose receiver is a range, and the one here that reads no accessor. It walks for x in r, so lupin 0.1.36, which resolves lazily, runs it over range[int] and declines range[char] itself ("a range needs integer endpoints"). Its int example is fenced for that reason.
rev() and step_by() remain BLOCKED on the iterator combinator surface (F-0008's successor); the combinator that truncates a sequence is named limit(n), never take(n) — take is the ownership mode that CONSUMES its operand, and a combinator that does not consume would be a false friend at the centre of the ownership story (wolf-lang#16, API-CONVENTIONS §10).
Functions and methods
fn · Source line 76
pub fn is_empty(r: range[int]) -> bool
True when r yields no values — 5..5 and 7..3 are empty, 2..7 is not. One comparison, r.start >= r.end; the body before 0.2.14 asked the iterator the same question (for _ in r { return false }), which was O(1) too and is why this function shipped eleven sprints before the other three. Total: no error row, no traps.
range.is_empty(5..5) == true
range.is_empty(7..3) == true
range.is_empty(2..7) == false
fn · Source line 93
pub fn contains(r: range[int], x: int) -> bool
True when x is a value r yields: r.start <= x && x < r.end, the spelling [type.range.accessor] gives. O(1) on every input, 0..9223372036854775807 included — the range this function refused to be written over by iteration. An empty range contains nothing. Total: no error row, no traps.
end is exclusive, so 7 is outside 2..7 and inside 2..=7:
range.contains(2..7, 2) == true
range.contains(2..7, 7) == false
range.contains(2..=7, 7) == true
fn · Source line 113
pub fn len(r: range[int]) -> int
The number of values r yields: r.end - r.start when r is non-empty, 0 when it is not — len(7..3) is 0 where the raw difference is -4 (module header), and len(a..=b) is b - a + 1 because end normalized to b + 1 at construction. No error row. Traps overflow (checked arithmetic, X3) when the count does not fit an int, which is exactly a range spanning more than half the integer line — (0 - 9223372036854775807 - 1)..9223372036854775807 yields 2^64 - 1 values and there is no int to say so; tests/range/len_overflow_trap.lu pins the kind.
range.len(2..7) == 5
range.len(2..=7) == 6
range.len(5..5) == 0
range.len(7..3) == 0
fn · Source line 135
pub fn clamp_to(r: range[int], x: int) -> int ! {none}
The value of r nearest to x: x itself when r contains it, r.start when x lies below, and r.end - 1 — the last value yielded — when x is at or above end. Rows: none when r is empty, because an empty range has no member to answer with (§2). Never traps: r.end - 1 is computed only under r.start < r.end, so it cannot underflow.
An empty range answers with the row, handled here with else:
(range.clamp_to(2..7, 4) else 0 - 1) == 4
(range.clamp_to(2..7, 9) else 0 - 1) == 6
(range.clamp_to(2..7, 0 - 3) else 0 - 1) == 2
(range.clamp_to(5..5, 1) else 0 - 1) == 0 - 1
fn · Source line 182
pub fn collect[T](r: range[T]) -> List[T]
A fresh list holding every value r yields, in iteration order: the values a for x in r would see. 2..5 collects 2, 3, 4; an empty or reversed range collects the empty list. One generic function for both element types the clause names (range[int], range[char]), because wolf has no overloading and a range[int] signature refuses a char range with E0401 (measured). Total: no error row; traps as the range's for does ([mem.iter.range]), and allocation. A 0..9223372036854775807 collect is a list of that length, which no host has, so no test here builds one.
[type.comb.set] (wolf-lang 4c046f15): the method r.collect() is this call (std.range is range's home module, [type.method.home]). Cost, as the clause states it: one fresh List of the range's length, plus push's own copy per value.
r is a read parameter and the values escape in the returned list ([mem.tier0.mode.read], wolf-lang#366, in 0.2.15), and that clause counts a TYPE PARAMETER as able to reach shared storage always, "because a generic body is checked once for every instantiation" — so T is in scope for the rule even though the two element types a range can have are scalars. No copy is spelled: the store is push's, wolf-lang#385 ruled option 3 (s167, unreleased) copies a non-Copy element by default, and a value that reaches no heap storage is its own copy, so this costs nothing at run time either way ([mem.tier0.move.3], wolf-lang#384). take is not the spelling here: a value moved out of a read parameter is LENT, and a take of a lent binding is E1014 by the same clause.
range.collect(2..5).len == 3
range.collect(2..5)[0] == 2
range.collect(1..=3)[2] == 3
range.collect(7..3).len == 0