fix `procedure-reduce-keyword-arity' checking
and clarify need for distinct keywords in parts of the documentation
This commit is contained in:
parent
3736571ad0
commit
7be0c8236f
|
@ -221,7 +221,7 @@
|
||||||
(loop (cdr ks))]
|
(loop (cdr ks))]
|
||||||
[(keyword<? (car ks) (cadr ks))
|
[(keyword<? (car ks) (cadr ks))
|
||||||
(loop (cdr ks))]
|
(loop (cdr ks))]
|
||||||
[else (type-error "sorted list of keywords" 1)]))
|
[else (type-error "sorted list of distinct keywords" 1)]))
|
||||||
(unless (list? kw-vals)
|
(unless (list? kw-vals)
|
||||||
(type-error "list" 2))
|
(type-error "list" 2))
|
||||||
(unless (= (length kws) (length kw-vals))
|
(unless (= (length kws) (length kw-vals))
|
||||||
|
@ -1044,13 +1044,13 @@
|
||||||
|
|
||||||
(unless (and (list? req-kw) (andmap keyword? req-kw)
|
(unless (and (list? req-kw) (andmap keyword? req-kw)
|
||||||
(sorted? req-kw))
|
(sorted? req-kw))
|
||||||
(raise-type-error 'procedure-reduce-keyword-arity "sorted list of keywords"
|
(raise-type-error 'procedure-reduce-keyword-arity "sorted list of distinct keywords"
|
||||||
2 proc arity req-kw allowed-kw))
|
2 proc arity req-kw allowed-kw))
|
||||||
(when allowed-kw
|
(when allowed-kw
|
||||||
(unless (and (list? allowed-kw) (andmap keyword? allowed-kw)
|
(unless (and (list? allowed-kw) (andmap keyword? allowed-kw)
|
||||||
(sorted? allowed-kw))
|
(sorted? allowed-kw))
|
||||||
(raise-type-error 'procedure-reduce-keyword-arity "sorted list of keywords or #f"
|
(raise-type-error 'procedure-reduce-keyword-arity "sorted list of distinct keywords or #f"
|
||||||
2 proc arity req-kw allowed-kw))
|
3 proc arity req-kw allowed-kw))
|
||||||
(unless (subset? req-kw allowed-kw)
|
(unless (subset? req-kw allowed-kw)
|
||||||
(raise-mismatch-error 'procedure-reduce-keyword-arity
|
(raise-mismatch-error 'procedure-reduce-keyword-arity
|
||||||
"allowed-keyword list does not include all required keywords: "
|
"allowed-keyword list does not include all required keywords: "
|
||||||
|
|
|
@ -216,9 +216,9 @@ arity-reduced procedure) or @racket[arity] must be the empty list
|
||||||
(or/c (listof keyword?) #f))]{
|
(or/c (listof keyword?) #f))]{
|
||||||
|
|
||||||
Returns information about the keyword arguments required and accepted
|
Returns information about the keyword arguments required and accepted
|
||||||
by a procedure. The first result is a list of keywords (sorted by
|
by a procedure. The first result is a list of distinct keywords (sorted by
|
||||||
@racket[keyword<?]) that are required when applying @racket[proc]. The
|
@racket[keyword<?]) that are required when applying @racket[proc]. The
|
||||||
second result is a list of accepted keywords (sorted by
|
second result is a list of distinct accepted keywords (sorted by
|
||||||
@racket[keyword<?]), or @racket[#f] to mean that any keyword is
|
@racket[keyword<?]), or @racket[#f] to mean that any keyword is
|
||||||
accepted. When the second result is a list, every element in the first
|
accepted. When the second result is a list, every element in the first
|
||||||
list is also in the second list.
|
list is also in the second list.
|
||||||
|
@ -239,7 +239,7 @@ requiring any keyword arguments). See also
|
||||||
@racket[procedure-reduce-keyword-arity].
|
@racket[procedure-reduce-keyword-arity].
|
||||||
|
|
||||||
When the result is called with keyword arguments, then @racket[proc]
|
When the result is called with keyword arguments, then @racket[proc]
|
||||||
is called; the first argument is a list of keywords sorted by
|
is called; the first argument is a list of distinct keywords sorted by
|
||||||
@racket[keyword<?], the second argument is a parallel list containing a
|
@racket[keyword<?], the second argument is a parallel list containing a
|
||||||
value for each keyword, and the remaining arguments are the
|
value for each keyword, and the remaining arguments are the
|
||||||
by-position arguments.
|
by-position arguments.
|
||||||
|
@ -266,7 +266,7 @@ obtains its result from @racket[plain-proc].
|
||||||
|
|
||||||
Like @racket[procedure-reduce-arity], but constrains the keyword
|
Like @racket[procedure-reduce-arity], but constrains the keyword
|
||||||
arguments according to @racket[required-kws] and @racket[allowed-kws],
|
arguments according to @racket[required-kws] and @racket[allowed-kws],
|
||||||
which must be sorted using @racket[keyword<?]. If @racket[allowed-kws]
|
which must be sorted using @racket[keyword<?] and contain no duplicates. If @racket[allowed-kws]
|
||||||
is @racket[#f], then the resulting procedure still accepts any
|
is @racket[#f], then the resulting procedure still accepts any
|
||||||
keyword, otherwise the keywords in @racket[required-kws] must be a
|
keyword, otherwise the keywords in @racket[required-kws] must be a
|
||||||
subset of those in @racket[allowed-kws]. The original @racket[proc]
|
subset of those in @racket[allowed-kws]. The original @racket[proc]
|
||||||
|
|
|
@ -262,6 +262,14 @@
|
||||||
(try-combos (map add-chaperone procs) values)
|
(try-combos (map add-chaperone procs) values)
|
||||||
(try-combos (map add-chaperone procs) add-chaperone)))
|
(try-combos (map add-chaperone procs) add-chaperone)))
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
;; Check error reporting of `procedure-reduce-keyword-arity'
|
||||||
|
|
||||||
|
(err/rt-test (procedure-reduce-keyword-arity void 1 '(#:b #:a) null)
|
||||||
|
(lambda (exn) (regexp-match #rx"3rd argument" (exn-message exn))))
|
||||||
|
(err/rt-test (procedure-reduce-keyword-arity void 1 null '(#:b #:a))
|
||||||
|
(lambda (exn) (regexp-match #rx"4th argument" (exn-message exn))))
|
||||||
|
|
||||||
;; ----------------------------------------
|
;; ----------------------------------------
|
||||||
|
|
||||||
(report-errs)
|
(report-errs)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user