Skip to content

verifier + interpreter: closure-bind ctx arg for srt/map/flt/fld#186

Merged
danieljohnmorris merged 1 commit into
mainfrom
fix/closure-bind-hofs
May 12, 2026
Merged

verifier + interpreter: closure-bind ctx arg for srt/map/flt/fld#186
danieljohnmorris merged 1 commit into
mainfrom
fix/closure-bind-hofs

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

HOFs were rejecting closures over outer scope. Verifier and interpreter now agree: a lambda passed to srt map flt fld threads its enclosing environment through on each call.

Implementation:

  • verifier: allow free variables in HOF lambda bodies if they resolve in the enclosing scope
  • interpreter: bind captured env when invoking the closure inside the builtin

Unlocks idiomatic top-N, key-fn sort, and reduce-with-accumulator patterns.

Tests: cross-engine regression tests + examples/closure-bind.ilo with -- run: directives.

HOFs like srt map flt fld accept an inline lambda for the predicate.
The lambda needs access to the outer scope (ctx). The verifier was
rejecting closures over ctx, and the interpreter was not binding the
captured environment. Both sides now agree: a closure passed to a HOF
gets its enclosing scope threaded through on each call.

Unlocks idiomatic top-N, key-fn sort, and group-style reductions.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 99.23077% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/verify.rs 98.88% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@danieljohnmorris danieljohnmorris merged commit e6ee66b into main May 12, 2026
5 checks passed
@danieljohnmorris danieljohnmorris deleted the fix/closure-bind-hofs branch May 12, 2026 09:04
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