Skip to content

Add optional LAMBDA input parameters with ISOMITTED defaults#98

Merged
jimmytacks merged 4 commits into
mainfrom
issue-93-optional-lambda-params
Apr 21, 2026
Merged

Add optional LAMBDA input parameters with ISOMITTED defaults#98
jimmytacks merged 4 commits into
mainfrom
issue-93-optional-lambda-params

Conversation

@jimmytacks
Copy link
Copy Markdown
Collaborator

@jimmytacks jimmytacks commented Apr 21, 2026

Summary

  • Adds a per-row "Optional" checkbox in the LET→LAMBDA dialog; disabled and auto-cleared when Keep is unchecked.
  • When a kept input is marked optional, the generated LAMBDA wraps it with IF(ISOMITTED(param), <original RHS>, param) inside an inner LET, so callers can omit the argument and the source-cell value acts as the default.
  • Optional-wrapper LET bindings are emitted before any internal bindings so internal bindings can reference the defaulted value. When no parameter is optional, output is byte-for-byte identical to today's.

Example

Input =LET(x, 10, y, A1, x + y), keep both, rename yoffset, mark offset optional:

=LAMBDA(x, offset, LET(offset, IF(ISOMITTED(offset), A1, offset), x + offset))

Test plan

  • dotnet test addin/lambda-boss.Tests/lambda-boss.Tests.csproj — 374 passed, including 8 new tests covering single/multiple optional params, optional + rename, optional + reorder, optional + internal bindings, optional-only (no internal LET), rejection of optional-on-unchecked, and no-optional byte-parity.
  • dotnet build addin/lambda-boss.slnx — builds clean.
  • In Excel: open a =LET(...) cell, run "LET to LAMBDA", mark a row Optional, Save, and invoke the generated LAMBDA with and without the optional argument.
  • Verify the Optional checkbox is disabled when Keep is off and auto-clears on Keep toggle off.

Closes #93

🤖 Generated with Claude Code

jimmytacks and others added 4 commits April 21, 2026 16:25
Extends the LET→LAMBDA dialog with a per-row "Optional" checkbox.
When set, the generated LAMBDA wraps that parameter with
IF(ISOMITTED(param), <original RHS>, param) via an inner LET binding,
so callers can omit the argument and the original source-cell value
is used as the default.

Optional-parameter LET bindings are emitted before any internal LET
bindings from the source, so internal bindings see the defaulted
value. When no parameter is optional, output is byte-for-byte
identical to today's.

Optional is disabled and auto-cleared when Keep is unchecked; the
builder also rejects IsOptional on a non-kept input.

Closes #93

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- LAMBDA signature now wraps optional parameter names with [] per
  Excel's optional-argument convention (e.g. LAMBDA(x, [offset], ...)).
  The inner LET binding, body references, and ISOMITTED argument
  continue to use the bare name.
- The row's RHS preview now reads "default: <rhs>" when Optional is
  checked, making the role of the RHS as the default expression
  explicit. Uncheck Optional (or Keep) and it reverts to the raw RHS.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Excel's Names.Add interprets relative A1 references in the formula
relative to the active cell at the time of the call. With the WPF
popup intercepting focus between formula capture and injection, the
active cell can drift from the source cell — baking an incorrect
anchor into the Name, so calls to the LAMBDA (even from the source
cell) resolve references shifted by the drift distance.

Re-select the captured source cell on Excel's macro thread via
QueueAsMacro immediately before Names.Add, restoring the expected
anchor. This keeps the source RHS text verbatim (no absolute-ifying)
and preserves the usual relative-reference semantics for callers.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Excel stores workbook-scoped LAMBDA Names with relative references
anchored to the active cell at registration time; invocations from
any other cell shift the refs by the offset, which baked wrong
defaults into ISOMITTED wrappers. Re-anchoring to the source cell
before Names.Add did not help in practice, so force cell refs in
optional default expressions to fully absolute form ($A$1) so they
resolve consistently regardless of where the LAMBDA is called from.

Ranges, sheet-qualified refs, and mixed absolute refs are handled;
tokens inside string literals are left alone.

A warning appears below the inputs list whenever at least one row is
marked Optional, making the transformation explicit to the author.

Also reverts the earlier Names.Add anchor attempt in the command
handler, since it didn't resolve the underlying issue.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jimmytacks jimmytacks merged commit f50e8af into main Apr 21, 2026
1 check passed
@jimmytacks jimmytacks deleted the issue-93-optional-lambda-params branch April 21, 2026 16:45
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.

Optional LAMBDA input parameters with ISOMITTED defaults

1 participant