1
0
forked from alex-eg/sex

tell a spec default by its body, not its length

A required method with a docstring or a comment counted as a default:
the realization could leave it out, and got a prototype with no
definition or a function with no return.
This commit is contained in:
2026-10-14 15:54:07 +03:00
parent 0119c85ded
commit f5c53cdd41
2 changed files with 29 additions and 2 deletions

View File

@@ -346,11 +346,21 @@
(append (map (lambda (g) (cons g #t)) given)
(filter-map
(lambda (w)
(and (> (length w) 4) ; carries a body, so a default
(and (spec-default? w)
(not (find (lambda (g) (eq? (second g) (second w))) given))
(cons (substitute-parameter parameter type w) #f)))
wanted)))
;;; A docstring or a comment is not a body, so
;;;
;;; (fn s ((self (* const T))) void "what s is for")
;;;
;;; is still a method every realization has to write.
(define (spec-default? method)
(let-values (((doc fn) (extract-fn-docstring (strip-fn-header-comments method))))
(any (lambda (form) (not (comment-form? form)))
(drop fn (fn-header-length fn)))))
(define (check-realization form name type parameter wanted given)
(for-each
(lambda (g)
@@ -369,7 +379,7 @@
given)
(let ((missing (filter-map
(lambda (w)
(and (= (length w) 4) ; no body, so required
(and (not (spec-default? w))
(not (find (lambda (g) (eq? (second g) (second w))) given))
(second w)))
wanted)))