Repository navigation
Eta-wrap user functions passed as higher-order callbacks (#343) - #344
Merged
Merged
Conversation
A relative cell ref inside a user lambda (e.g. LAMBDA(v, v=C3)) silently re-anchors when that lambda is passed directly as a MAP/SCAN/REDUCE/GROUPBY callback inside a defined-name lambda: Excel re-reads it as an offset-from-A1 applied to the formula cell, usually hitting an empty cell - silent wrong answers. Wrapping the call in an owned lambda of matching arity preserves the closure. Affected call sites fixed: GRIDWHERE, CLUSTERAGG (predicate + value_fn), ALL, ANY, COUNTOF, SCANLEAD, MOSTOF (GROUPBY forward), CUMSUMGRID (x2), REDUCE1, SCAN1. Each gains a closure regression test (arity/semantics only - the harness formula lives at A1 where the re-anchoring is the identity, so the bug itself is invisible there; verification was COM-based with formulas away from A1, full 139-name library injected). The create-lambda skill gains the eta-wrap rule. Closes #343 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #343
Summary
Fixes the silent relative-reference re-anchoring Tim hit in GRIDWHERE (
LAMBDA(v, v=A1)predicates returning #N/A). Every library call site that passed a user-supplied function directly as a MAP/SCAN/REDUCE/GROUPBY callback now eta-wraps it in an owned lambda of matching arity, which preserves the closure:MAP(grid, LAMBDA(x_, predicate(x_)))predLAMBDA(acc_, x_, fn(acc_, x_))GROUPBY(_keys, _vals, LAMBDA(col_, _fn(col_)), 0, 0, -2)— COM-verified the wrap is transparent for the ROWS/SUM defaults and built-ins by nameSafe patterns left untouched: fns called inside owned callbacks (FOLDROWS, RUNGROUPBY, BIMAP, dispatchers), direct calls (BIROW/BICOL), built-ins passed by name where no user lambda can arrive.
The create-lambda skill best-practice section gains the eta-wrap rule with the diagnosis.
Testing