Skip to content

Unified patterns; is with patterns and bindings; defer expr; match x is Enum - #86

Merged
kryptamine merged 1 commit into
masterfrom
unified-patterns
Nov 16, 2026
Merged

kryptamine merged 1 commit into
masterfrom
unified-patterns

Conversation

@kryptamine

Copy link
Copy Markdown
Owner

What

  • One pattern grammar everywhere: let, parameters and for take nested patterns (let { user: { name, tags: [first, ...more] } } = r;); match patterns take defaults and object rest ({ name, role = "member", ...extra }, [cmd, target = "."]). A key may repeat to bind and take apart ({ pos, pos: { x } }).
  • let patterns only take values apart; literals, ranges, | or types there are a compile error.
  • v is P takes any pattern: x is 1..10, x is "a" | "b", r is { status: 200..300 }, S.A is S.A, x is LIMIT. Bare names are types, unless they name a constant or a unit variant.
  • In an if or while condition, is binds: if r is { status: 200, body } && body { ... }, while q.pop() is { id } { ... }, name is P binds the whole value. Binding elsewhere, after !is or || is a compile error.
  • defer expr;; defer { single; } is an error (one way).
  • match s is Status { Pending => ..., Paid | Shipped => ..., Card { brand } => ... }: bare variants, coverage checked, unknown names caught, non-Status value is a no-match error.

Notes

  • p is 1 was a runtime TypeError, now a literal test (false).
  • The is type error points at the type now.
  • Pattern code lives in compile_pattern.go and resolve_pattern.go; compile_expr.go and resolver.go shrank below their previous sizes.
  • Bytecode of programs without patterns or is is unchanged; conditions with is now compile to JMPNOTTYPE chains.

Tests

New scripts in test/destructure, test/match, test/is, test/defer; docs examples re-run; 90s fuzz clean.

…n and binds in if/while; defer expr; match x is Enum

- let, parameters and for-in take nested patterns; match patterns take defaults and object rest
- let patterns only take values apart; testing patterns there is a compile error
- v is P matches any pattern (bare names are types, constants and unit variants are values)
- is in an if or while condition binds variables for the body and the right of &&
- defer expr; a braced single expression is an error
- match x is Enum { Variant => ... } names variants bare, checks coverage
- pattern code moves to compile_pattern.go and resolve_pattern.go
@kryptamine
kryptamine merged commit 08f3ea1 into master Nov 16, 2026
3 checks passed
@kryptamine
kryptamine deleted the unified-patterns branch November 16, 2026 17:47
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.

1 participant