Repository navigation
Description
Restated 2026-10-25. str.fields() landed (awk's $N and NF work). What is left: str has no parse(), so a field cannot become a number in a one-liner or ordinary code. The only integer parser is the free function std.string.parse(s) -> i32. Eric's review of #2127 set the shape: one generic parse() whose result type comes from its use (a typed binding, ?? 0 against an i64), with parse[T]() when nothing decides it; never parse_i64.
Original report
What
From the 2026-09-03 sed/awk parity matrix (seed v0.15.1.7-g54651442e). awk's default field splitting is on runs of whitespace with leading/trailing blanks ignored; With's str has only split(sep) on an exact separator, so:
$ printf 'beta 20 y\n' | with -n 'print(line.split(" ").get(1))'
→ "" (the empty field between the two spaces)
$ … | with -n 'print(line.fields().get(1))'
error: unknown method 'fields' for type '&str'
wc -w via split(" ").len() overcounts for the same reason (18 for 17 words on the matrix input). No split_whitespace/fields/words exists anywhere in lib/std (verified by grep) — docs/improve_oneliners.md already lists "Count words on each line" and "Print the first word of each line" under "Missing Unicode and text conveniences" for this reason.
Integer parsing: str has no parse method (parse, parse_int, to_int, to_i64, parse_i64 all "unknown method"); the only parser is std.string.parse(s: &str) -> i32 (lib/std/string.w:236) — a free function, i32 only, and not an implicit one-liner import. awk's $2 + 0, {s += $2} therefore have no direct spelling; docs/improve_oneliners.md "Explicit parsing, typing, and empty-case handling" is the same gap from the cookbook side.
Proposal
str.fields() -> Vec[str](whitespace runs, blanks ignored; the awk/Go/Rustsplit_whitespacecontract), and the-n/-pcheat-sheet mapsawk '{print $N}'toline.fields().get(N-1).str.parse_i64() -> Option[i64](andparse_f64), anOptionbecause a non-number is normal input, so?/??/unwrap_orread naturally:total = total + line.fields().get(1).parse_i64() ?? 0.- Keep
std.string.parseas it is or make it thei32twin; do not widen it silently.
Acceptance: the matrix rows awk '{print $2}', awk -F: NF, awk '{s+=$2} END{print s}' (with #957) and wc -w join the cli-selfhost-one-liner-tests lane. Companions: #957 (state/END), #958 (file operands, -i).
Activity
str.fields() and str.parse_i64(): awk's $N and $N + 0 for one-liners (w…
str.fields(): awk's $N for one-liners (withlang-dev#959)
str.fields(): awk's $N for one-liners (withlang-dev#959)
str.fields(): awk's $N for one-liners (#959) (#2127)
[-]str: no whitespace-run field splitting (awk's $N) and no integer parse method — one-liners cannot spell awk '{print $2}' or '$2+0'[/-][+]str: no parse() typed by use — a field cannot become a number (fields() landed)[/+]ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): reproduced.The same error appears for an owned
str("12".parse()).line.fields().len()works and prints the field count.pre-release: ordinary code that reads numbers from text hits it, and the shape is already decided by the #2127 review.
ehartford commentedon Oct 26, 2026
Fix campaign, 2026-10-25: flagged
human attn needed. Left ondo-before-release.Built and proved (branch
fix-959, not merged).pub fn parse[T: Parse]() -> Option[T]onstr, strict, typed by its use;trait Parseimplemented for the integer types andf64(strtod's correctly rounded double). Three Sema gaps had to close for it, each with a test:impl str) was never instantiated: "BUG: user generic call lacks a concrete contract";let n: Option[i64] = cell.get()was "cannot infer generic method type parameter";??carrier got no expectation, solet n: i64 = s.parse() ?? 0could not infer.The shape follows the #2127 review, and I recorded the design as delegated decision D160.
Why it is not merged. The stack's battery found two problems:
text |> parse |> match:intest/behavior/behav_pipeline_match.wandspec_ss09_7_pipeline_match.wnow resolves to the newstr.parseinstead of the program's ownfn parse(text: str) -> Result[..], because §9.6 says "that method takes precedence over a same-named free function". Withparseonstr, any program that pipes astrinto its ownparsechanges meaning.plain-bits-field-copy-annotationin src 0 → 417,some-at-option-demandin lib 1 → 17). I have not traced it yet; the expectation the Sema changes add is the likely cause.Narrowest open question. When a pipeline stage names both a method of the value and a visible free function, and the method is generic with a type parameter nothing at the stage can infer, should the stage fall back to the free function (the method counts as not applicable, extending §9.6's "if no applicable method exists")? Or does a program's own declaration simply win (§18.1)?
Brief:
useimports win over prelude names".parseand declared it; a std method silently taking the name is a meaning the program did not choose. Program-declared names winning is the with-y reading.parse.Below the 75% bar for a delegated decision, so it waits. The census rise gets traced when the stage rule is settled.
std, Sema: str.parse() turns text into a number of the type its use d…
ehartford commentedon Oct 27, 2026
Fixed on main in e040b90 (#2752), delegated as D165 (renumbering the unmerged branch's D160):
str.parse[T: Parse]() -> Option[T], strict whole-text parsing typed by its use, for the integer types and f64. The two remaining Sema gaps are closed (a generic method of a builtin owner was never instantiated; a method type parameter no argument mentions now takes the result demand).What parked the branch is resolved in the same change:
input |> parsestays the program's ownparse(nothing at the stage determinesstr.parse'sT); underlet n: Option[i64] = text |> parsethe demand determines it and the method applies; with no same-named free function the refusal still names the missing type. Verified as a four-way matrix on stage1. Prediction 80% for this reading of §9.6.Some(...)wrappers at Option demands in the new string.w code and two typed field lets in the new Sema code. Removed; counts are back to main's (plain-bits 416, the D144 allowance ceiling; some-at lib 1, src 7).Tests behav_959_str_parse_by_use and behav_959_generic_method_typed_by_result (both fail pre-fix), with the two pipeline_match fixtures as the collision regression.