The documentation for ->*
mentions a particular contract not matching (λ (x . rest) x)
due to the rest args not being optional, but I was unable to find a contract that does match that function.
What contract matches that function?
The documentation for ->*
mentions a particular contract not matching (λ (x . rest) x)
due to the rest args not being optional, but I was unable to find a contract that does match that function.
What contract matches that function?
Rubber duck works again
[ zipn (-> list? ... list?) ]
Of course, my scenario is simplified since all the rest args are of the same type.
The contract (->* (integer?) #:rest (listof integer?) any)
should do the trick.
The REPL seems to agree.
% rlwrap racket
Welcome to Racket v8.2 [cs].
> (define/contract (f x . rest)
(->* (integer?) #:rest (listof integer?) any)
x)
> (f 2)
2
> (f 2 3 4)
2
> (f "racket" 2 3 4)
f: contract violation
expected: integer?
given: "racket"
in: the 1st argument of
(->*
(integer?)
#:rest
(listof integer?)
any)
contract from: (function f)
blaming: top-level
(assuming the contract is correct)
at: stdin::50-51
context...:
/usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/blame.rkt:346:0: raise-blame-error
/usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/arrow-higher-order.rkt:375:33
/usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/repl.rkt:11:26
> (f 2 "racket" "rhombus" "scribble")
f: contract violation
expected: integer?
given: "racket"
in: an element of
the rest argument of
(->*
(integer?)
#:rest
(listof integer?)
any)
contract from: (function f)
blaming: top-level
(assuming the contract is correct)
at: stdin::50-51
context...:
/usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/blame.rkt:346:0: raise-blame-error
/usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/list.rkt:215:14
/usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/arrow-higher-order.rkt:375:33
/usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/repl.rkt:11:26