Skip to content

Another attempt to generate smarter arity-inspectable case-lambdas - #1189

Merged
ashinn merged 6 commits into
ashinn:masterfrom
aartaka:case-lambda-better-arity-2
Sep 2, 2026
Merged

ashinn merged 6 commits into
ashinn:masterfrom
aartaka:case-lambda-better-arity-2

Conversation

@aartaka

@aartaka aartaka commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Yes, I’m at it again—trying to make case-lambda-generated lambdas to have more inspectable and truthful arities. This time, the implementation is short (17 lines -> 30 lines,) tested, documented, and more straightforward in general. Expansion time shouln’t be too long either, especially compared to the previous attempt (#1167), where a whole set of recursive macros handling arglists was used.

@ashinn how does that look?

Comment thread lib/srfi/16.sld Outdated
;; by rest arg
((%case-lambda ((arg . _) ...) non-parsed-args clauses ...)
(lambda (arg ... . rest)
(let ((len (length `((unquote arg) ... . (unquote rest)))))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Currently Chibi doesn't constant fold length on a constant list but I'm likely to implement that. Even without the folding, there's no reason to construct a list at runtime here:

Suggested change
(let ((len (length `((unquote arg) ... . (unquote rest)))))
(let ((len (+ (length '(arg ...)) (length rest))))

@aartaka

aartaka commented Sep 2, 2026 via email

Copy link
Copy Markdown
Contributor Author

@ashinn
ashinn merged commit 8f94a5e into ashinn:master Sep 2, 2026
7 of 8 checks passed
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.

2 participants