1
0
forked from alex-eg/sex

define an empty lambda as an empty function

A lifted function with no body was a declaration of one, and nothing
defined it, so the program did not link.
This commit is contained in:
2026-10-18 22:02:55 +03:00
parent b3d7decc6b
commit 94f41b5fad
5 changed files with 45 additions and 10 deletions

View File

@@ -1505,10 +1505,17 @@
(string->symbol
(fmt #f "λ" counter "_" enclosing-fn-name)))
;;; A function with no body is a declaration, and nothing would define
;;; one lifted from an empty lambda; an empty block keeps it a definition,
;;; and the writer leaves the block out
(define (defining body)
(if (every comment-form? body) (append body (list '(do))) body))
(define (lift-lambda name form)
(match form
(('lambda arglist ret-type . body)
(process-fn (copy-form-source! form `(fn ,name ,arglist ,ret-type ,@body))
(process-fn (copy-form-source! form `(fn ,name ,arglist ,ret-type
,@(defining body)))
(list)))
(else (sex-error form "malformed lambda" form))))
@@ -1844,11 +1851,13 @@
(list
`(fn ,code ((ƛe (* void)) ,@(named-parameters arglist)) ,ret-type
,@(if (null? caps)
(list)
`((var ƛcaptures (* (struct ,record)) ƛe)
,@(append-map (cut capture-local <> form) caps)))
,@body)
,@(defining
(append
(if (null? caps)
(list)
`((var ƛcaptures (* (struct ,record)) ƛe)
,@(append-map (cut capture-local <> form) caps)))
body)))
`(fn ,construct ,caps (struct ,closure)
(var ƛc (struct ,closure))