Conversation
Add a CaseLambda AST node and CaseLambdaClosure runtime value that dispatch an application to the first clause whose formals accept the supplied argument count, reusing the existing lambda formal-binding and free-variable capture machinery.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #82 +/- ##
==========================================
+ Coverage 73.19% 73.60% +0.40%
==========================================
Files 24 24
Lines 2108 2239 +131
Branches 290 309 +19
==========================================
+ Hits 1543 1648 +105
- Misses 565 591 +26
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82e839bccb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| void CaseLambdaClosure::dump() const { | ||
| llvm::dbgs() << "<case-lambda closure: not implemented>\n"; | ||
| } | ||
| void CaseLambdaClosure::write() const {} No newline at end of file |
There was a problem hiding this comment.
When a case-lambda value is returned instead of immediately applied, such as (linklet () () (case-lambda ((x) x))), interpretation produces a CaseLambdaClosure and main prints it through ValueNode::write(). This override is empty, so the program emits only the trailing newline instead of the procedure representation provided by CaseLambda::write(), making procedure-valued results disappear.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Out of scope for this PR — you're right that a bare top-level case-lambda prints only a newline because CaseLambdaClosure::write() is empty. But that is exact parity with the existing Closure::write() (the plain-lambda runtime value, also empty at src/ASTRuntime.cpp:45), so this PR introduces no case-lambda-specific regression. The proper fix gives both procedure writers a #<procedure> representation together — changing only the case-lambda one would make the two procedure kinds inconsistent — which belongs in a separate printing-focused change rather than in "Interpret case-lambda".
This assessment was made by two independent AI reviewers (Claude Opus 4.8 and Codex). If you disagree, please reply and we'll re-evaluate.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Summary
CaseLambdaAST node (a sequence oflambdaclauses) and aCaseLambdaClosureruntime value, so(case-lambda (formals body) ...)parses, evaluates to a closure, and captures free variables across all clauses.>=for a rest formal, any count for a bare identifier), then binds and evaluates that clause's body.lambdaandcase-lambdashare is factored into anInterpreter::applyFormalshelper; clause selection uses a smallformalsAcceptpredicate.Fixes #3
Test plan
ctest --preset debug— 14/14 unit tests pass, including a newParsing case-lambdacase (fixed, rest, and empty-clause forms)nora-lit test/integration— 53/53 pass, including 5 newcase-lambda*.rkttests: arity dispatch, rest-formal clause, identifier (all-args) fallthrough clause, and free-variable capture withset!/let-valuescmake --build --preset debug— clean (warnings-as-errors)clang-format(v22.1.5) — all edited files clean