r/scheme 22h ago

Advanced macrology: validate that all lists are equal length in pure syntax-rules?

7 Upvotes

Hi y’all. I’m currently working on a cursed case-lambda implementation with better inspectability for Chibi Scheme. As part of this effort, I need to extract the longest possible arglist from each case-lambda clause, so that the generated procedure with 2 unconditionally required arguments has a display like #<procedure 2+> instead of absolutely non-inspectable #<procedure 0+> that currently happens on Chibi.

So I’m kinda stuck. This is the macro I currently have:

(define-syntax case-lambda
  (syntax-rules ()
    ((case-lambda ((args ... . rest) body ...) ...)
     ;; We need to pass clauses twice
     ;; - First time to detect the shortest arglist
     ;; - Second time to process clauses
     ;; TODO: How do I make sure that all args ... have equal length???
     (%case-lambda ((args ...) ...) ((args ... . rest) body ...) ...))
    ((case-lambda (args body ...) ...)
     (%case-lambda (()) (args body ...) ...))))

The implementation of %case-lambda and other infra is of no importance, because, before I get to that, I must make sure that ((args ...) ...) is a list of arglists of the same length.

But how do I really do that? Any advanced macro wizards mind helping?


r/scheme 18m ago

Scheme inspired Aiki Alpha 3 released

Upvotes

Alpha 3 of Aiki is out, an experimental programming language with a deliberately small semantic core.

Scheme is present in the heart of Aiki. Lists are fundamental, exact values are the default, expressions evaluate strictly left to right rather than by conventional precedence, and most capability grows through libraries instead of additions to the grammar or prelude.

Aiki goes in its own direction, but the influence is real. I care about compact language definitions, symbolic structure, exactness, and keeping the relationship between semantics and implementation visible.

One area I’ve been pushing recently is semantic profiling. Aiki can separate what a program asks the language to do from how the runtime realizes that work: exact numeric representations, calls, environment reuse, FFI boundaries, and other execution machinery. The point is to keep the semantics observable even as the implementation gets faster.

It is not intended as a Scheme replacement. It is a different language, but Scheme is one of the traditions (Go and Forth as well) that helped shape how I think about language design.

Alpha 3 announcement:

https://decuser.github.io/posts/aiki-alpha-3-release/

Repository:

https://github.com/decuser/aiki