Skip to content

One-liners keep state by position: -e before and after the -n/-p loop, and 'last' (D217, #957) - #3448

Merged
ehartford merged 2 commits into
mainfrom
oneliners-state-and-files
Nov 19, 2026
Merged

ehartford merged 2 commits into
mainfrom
oneliners-state-and-files

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Closes #957. Delegated (D98; D217 records the brief): a CLI surface, easy to reverse, prediction 75%.

  • -e by position. Beside -n or -p, -e code before the first loop part runs once before the loop and -e code after the last runs once after it. -e between two loop parts is an error that says where each belongs. -n with -p is still refused.
  • last is bound to whether the current line is the final one, when the code names it and does not declare its own.
  • A var in loop code is not hoisted: it is the loop body's, as in any loop.
with -e 'var m = ""' -n 'if line.len() > m.len(): m = line' -e 'print(m)'   # longest line
with -n '' -e 'print(nr)'                                                       # wc -l (0 on empty input)
with -n 'if last: print(line)'                                                  # tail -n 1

Diagnostics still point at the user's argument (<cli -e #2> for code after the loop). One helper now appends a code part and maps it; the harness gains six cases; spec v7.65 (§18.5b.3 and the one-liner document); the instructions' parity table and the gap list are brought up to date.

Battery green on the branch tip.

@ehartford
ehartford merged commit c810be3 into main Nov 19, 2026
@ehartford
ehartford deleted the oneliners-state-and-files branch November 19, 2026 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

one-liners: -n/-p have no persistent state across lines and no END/last — sums, counts, uniq, tail, last line, regex ranges are inexpressible

1 participant