Add optional LAMBDA input parameters with ISOMITTED defaults#98
Merged
Conversation
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>
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.
Summary
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.Example
Input
=LET(x, 10, y, A1, x + y), keep both, renamey→offset, markoffsetoptional: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.=LET(...)cell, run "LET to LAMBDA", mark a row Optional, Save, and invoke the generated LAMBDA with and without the optional argument.Closes #93
🤖 Generated with Claude Code