Re: SRFI 284: define-typed
Dr. Arne Babenhauserheide 25 Sep 2026 22:56 UTC
PS: a practical example for #:rest
> For define-typed* it would be possible to set a rest argument checking
> procedure via #:rest, but this check procedure then also receives all
> arguments defined via #:key.
(define (all-integer? x) (not (member #f (map integer? x))))
(define-typed* (foo name #:rest r) (string? #:rest all-integer? -> list?)
r)
(foo "hello" 1 2 3 4 5)
$1 = (1 2 3 4 5)
(foo "me" "hello" 1 2 3 4 5)
type error ~a ~a #<procedure all-integer? (x)> ("hello" 1 2 3 4 5)
(foo 1 2 3 4 5)
type error ~a ~a #<procedure string? (_)> 1
And a small aside: it’s pretty awesome that we can add this to Scheme
without needing any changes in the implementation.
An option to support rest arguments in define-typed (not only in
define-typed*) would be to go back to the initial version which had the
type in the first position instead of after ->
But that would require some more changes, because supporting return
types with lambda would require to either put single return types into
parentheses, too, or to use a specific marker for lists of return types.
This form:
(define-typed (count . a) (integer? . string?) (length a))
could be possible. But currently that’s a syntax error.
Then multiple value return would need:
(define-typed (vals . a) ((-> all-string?) . string?) (apply values a))
The simpler version
(define-typed (count a) (integer? list?) (length a))
(count '(1 2 3))
already works.
Best wishes,
Arne
--
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
https://www.draketo.de