name a lambda's unnamed parameters in its definition

A definition names every parameter before C23, as a closure's code
already does.
This commit is contained in:
2026-10-19 13:38:30 +03:00
parent 6ad8f8f56b
commit 1bdeda6cc3
2 changed files with 14 additions and 3 deletions

View File

@@ -1568,8 +1568,10 @@
(define (lift-lambda name form) (define (lift-lambda name form)
(match form (match form
(('lambda arglist ret-type . body) (('lambda arglist ret-type . body)
(process-fn (copy-form-source! form `(fn ,name ,arglist ,ret-type (process-fn (copy-form-source!
,@(defining body))) form
`(fn ,name ,(named-parameters arglist) ,ret-type
,@(defining body)))
(list))) (list)))
(else (sex-error form "malformed lambda" form)))) (else (sex-error form "malformed lambda" form))))
@@ -1935,7 +1937,8 @@
;;; type alone gets a name nothing reads: ((int) (b int)) -> ((ƛu0 int) (b int)) ;;; type alone gets a name nothing reads: ((int) (b int)) -> ((ƛu0 int) (b int))
(define (named-parameters arglist) (define (named-parameters arglist)
(map (lambda (arg index) (map (lambda (arg index)
(if (or (named-arg? arg) (comment-form? arg)) (if (or (named-arg? arg) (comment-form? arg)
(eq? arg '...) (equal? arg '(...)))
arg arg
(list (string->symbol (string-append "ƛu" (number->string index))) (list (string->symbol (string-append "ƛu" (number->string index)))
(unwrap-type arg)))) (unwrap-type arg))))

View File

@@ -490,6 +490,14 @@
(test-assert "and its code names it, a definition needing one before C23" (test-assert "and its code names it, a definition needing one before C23"
(emits? (in-fn "(var c (closure ((int) (int)) int) (closure ((int) (b int)) int () (return b)))") (emits? (in-fn "(var c (closure ((int) (int)) int) (closure ((int) (b int)) int () (return b)))")
"int ƛu0, int b)")) "int ƛu0, int b)"))
;; a definition names every parameter before C23, a lambda's as a
;; closure's code does
(test-assert "a lambda's unnamed parameter is named in its definition"
(emits? "(fn f () void (var g (fn ((int) (int)) int) (lambda ((int) (b int)) int (return b))))"
"λ0_f (int ƛu0, int b)"))
(test-assert "and a variadic one keeps its ..."
(emits? "(fn f () void (var g (fn ((int) ...) int) (lambda ((n int) ...) int (return n))))"
"λ0_f (int n, ...)"))
;; a lifted function with no body was a declaration of one, and ;; a lifted function with no body was a declaration of one, and
;; nothing defined it ;; nothing defined it
(test-assert "an empty lambda is an empty function" (test-assert "an empty lambda is an empty function"