fix `procedure-reduce-keyword-arity' checking

and clarify need for distinct keywords in parts of the
 documentation
This commit is contained in:
Matthew Flatt 2011-07-13 20:24:14 -06:00
parent 3736571ad0
commit 7be0c8236f
3 changed files with 16 additions and 8 deletions

View File

@ -221,7 +221,7 @@
(loop (cdr ks))]
[(keyword<? (car ks) (cadr 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)
(type-error "list" 2))
(unless (= (length kws) (length kw-vals))
@ -1044,13 +1044,13 @@
(unless (and (list? req-kw) (andmap keyword? 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))
(when allowed-kw
(unless (and (list? allowed-kw) (andmap keyword? allowed-kw)
(sorted? allowed-kw))
(raise-type-error 'procedure-reduce-keyword-arity "sorted list of keywords or #f"
2 proc arity req-kw allowed-kw))
(raise-type-error 'procedure-reduce-keyword-arity "sorted list of distinct keywords or #f"
3 proc arity req-kw allowed-kw))
(unless (subset? req-kw allowed-kw)
(raise-mismatch-error 'procedure-reduce-keyword-arity
"allowed-keyword list does not include all required keywords: "

View File

@ -216,9 +216,9 @@ arity-reduced procedure) or @racket[arity] must be the empty list
(or/c (listof keyword?) #f))]{
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
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
accepted. When the second result is a list, every element in the first
list is also in the second list.
@ -239,7 +239,7 @@ requiring any keyword arguments). See also
@racket[procedure-reduce-keyword-arity].
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
value for each keyword, and the remaining arguments are the
by-position arguments.
@ -266,7 +266,7 @@ obtains its result from @racket[plain-proc].
Like @racket[procedure-reduce-arity], but constrains the keyword
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
keyword, otherwise the keywords in @racket[required-kws] must be a
subset of those in @racket[allowed-kws]. The original @racket[proc]

View File

@ -262,6 +262,14 @@
(try-combos (map add-chaperone procs) values)
(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)