Skip to content

Interpret case-lambda#82

Merged
pmatos merged 1 commit into
mainfrom
issue-3
Jul 1, 2026
Merged

Interpret case-lambda#82
pmatos merged 1 commit into
mainfrom
issue-3

Conversation

@pmatos

@pmatos pmatos commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add a CaseLambda AST node (a sequence of lambda clauses) and a CaseLambdaClosure runtime value, so (case-lambda (formals body) ...) parses, evaluates to a closure, and captures free variables across all clauses.
  • Application now selects the first clause whose formals accept the supplied argument count (exact match for a fixed list, >= for a rest formal, any count for a bare identifier), then binds and evaluates that clause's body.
  • The clause-binding logic that lambda and case-lambda share is factored into an Interpreter::applyFormals helper; clause selection uses a small formalsAccept predicate.

Fixes #3

Test plan

  • ctest --preset debug — 14/14 unit tests pass, including a new Parsing case-lambda case (fixed, rest, and empty-clause forms)
  • nora-lit test/integration — 53/53 pass, including 5 new case-lambda*.rkt tests: arity dispatch, rest-formal clause, identifier (all-args) fallthrough clause, and free-variable capture with set!/let-values
  • cmake --build --preset debug — clean (warnings-as-errors)
  • clang-format (v22.1.5) — all edited files clean

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.
@pmatos pmatos mentioned this pull request Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.42857% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.60%. Comparing base (1ca9b29) to head (82e839b).

Files with missing lines Patch % Lines
src/Interpreter.cpp 78.37% 16 Missing ⚠️
src/Parse.cpp 78.37% 8 Missing ⚠️
src/AST.cpp 46.15% 7 Missing ⚠️
src/ASTRuntime.cpp 80.95% 4 Missing ⚠️
src/AnalysisFreeVars.cpp 75.00% 1 Missing ⚠️
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     
Flag Coverage Δ
integration 73.60% <79.42%> (+0.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/ASTRuntime.cpp
void CaseLambdaClosure::dump() const {
llvm::dbgs() << "<case-lambda closure: not implemented>\n";
}
void CaseLambdaClosure::write() const {} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Print case-lambda closures

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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Tracked as #85 (#85).

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.

@claude

claude Bot commented Jul 1, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@pmatos pmatos merged commit 6922772 into main Jul 1, 2026
20 checks passed
@pmatos pmatos deleted the issue-3 branch July 1, 2026 20:24
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.

Interpret case-lambda

1 participant