Skip to content

Add Edit Lambda command to expand LAMBDA call into LET#99

Merged
jimmytacks merged 3 commits into
mainfrom
issue-94-edit-lambda
Apr 22, 2026
Merged

Add Edit Lambda command to expand LAMBDA call into LET#99
jimmytacks merged 3 commits into
mainfrom
issue-94-edit-lambda

Conversation

@jimmytacks
Copy link
Copy Markdown
Collaborator

@jimmytacks jimmytacks commented Apr 21, 2026

Closes #94

Summary

  • Adds an Edit Lambda ribbon button (Generate group) that replaces the active cell's exact call to a registered LAMBDA with an equivalent =LET(...) inlining the LAMBDA's parameters bound to the call-site arguments.
  • New LambdaSignatureParser extracts (param1, ..., paramN, body) from a =LAMBDA(...) RefersTo (handles optional [x] brackets, nested commas, case-insensitive, whitespace-tolerant).
  • New EditLambdaCommand detects =Name(args...) shape exactly (rejects trailing content, missing parens), resolves the name via Name Manager, and builds the expanded LET. The LAMBDA Name definition is left in place so rerunning LET to LAMBDA with the same name overwrites it.
  • Clear errors for: non-LAMBDA-call cells, call-site arg count exceeding LAMBDA param count. Fewer call-site args than params leaves trailing params unbound (documented behaviour).

Example

MyCalc = =LAMBDA(x, y, x * y + 1), active cell = =MyCalc(A1, B1 + 2)
→ cell becomes =LET(x, A1, y, B1 + 2, x * y + 1).

Test plan

  • Unit tests: LambdaSignatureParserTests (14) and EditLambdaCommandTests (19) — 421 tests pass, 0 fail.
  • Smoke test in Excel: register a LAMBDA via LET to LAMBDA, call it in a cell, run Edit Lambda, confirm cell becomes the equivalent LET.
  • Round-trip test: edit the LET, run LET to LAMBDA with the same name, confirm the Name's RefersTo is updated (existing LambdaLoader.InjectLambda path).
  • Error paths: non-LAMBDA call (e.g. =SUM(A1:A10)), non-exact call (=MyCalc(A1) + 5), too many args — all show a clear message and make no change.

🤖 Generated with Claude Code

jimmytacks and others added 3 commits April 21, 2026 17:57
Adds a ribbon button that replaces the active cell's exact call to a
registered LAMBDA (e.g. =MyCalc(A1, B1 + 2)) with an equivalent =LET(...)
that inlines parameters bound to call-site arguments followed by the
LAMBDA body. The workbook Name definition is left untouched so rerunning
LET to LAMBDA with the same name overwrites it.

Closes #94

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…lash

With ExplicitExports=false, ExcelDNA auto-registers every public static
method as a UDF. Both command classes had a public static Run method,
causing 'Repeated function name: Run' on add-in load. Making them
internal keeps them reachable from the same-assembly RibbonController
while hiding them from UDF discovery.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- FormulaFormatter emits LET and LAMBDA blocks one binding/param per line
  at a 4-space indent, so both LET-to-LAMBDA storage and Edit Lambda
  output render legibly in Excel's formula bar and Name Manager.
- Edit Lambda now folds a LET body into the outer LET rather than
  producing a LET-inside-LET, giving a single flat LET after expansion.
- LET-to-LAMBDA dialog allows overwriting an existing LAMBDA with the
  same name (shown as an informational message, Save stays enabled).
  Names pointing to something that isn't a LAMBDA still block.
@jimmytacks jimmytacks merged commit a40be9f into main Apr 22, 2026
1 check passed
@jimmytacks jimmytacks deleted the issue-94-edit-lambda branch April 22, 2026 06:23
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.

Edit Lambda command — expand LAMBDA call back to LET in place

1 participant