diff --git a/collects/scribblings/guide/apply.scrbl b/collects/scribblings/guide/apply.scrbl index d0701a0434..20498c979d 100644 --- a/collects/scribblings/guide/apply.scrbl +++ b/collects/scribblings/guide/apply.scrbl @@ -135,5 +135,5 @@ list contains by-position procedure arguments, as for @scheme[apply]. (keyword-apply go '(#:mode) '(fast) - (list "super.ss")) + '("super.ss")) ] diff --git a/collects/scribblings/guide/lambda.scrbl b/collects/scribblings/guide/lambda.scrbl index 719502fd89..c8fb3f1fdf 100644 --- a/collects/scribblings/guide/lambda.scrbl +++ b/collects/scribblings/guide/lambda.scrbl @@ -182,8 +182,8 @@ The @scheme[lambda] form does not directly support the creation of a procedure that accepts ``rest'' keywords. To construct a procedure that accepts any and all keyword arguments, use @scheme[make-keyword-procedure]. The procedure supplied to -@scheme[make-keyword-procedure] receives keyword arguments throw -two parallel lists in the first two (by-position) arguments, and +@scheme[make-keyword-procedure] receives keyword arguments through +parallel lists in the first two (by-position) arguments, and then all by-position arguments from an application as the remaining by-position arguments. diff --git a/collects/scribblings/new-lambda.ss b/collects/scribblings/new-lambda.ss index 59d0cd12e0..7345c49f87 100644 --- a/collects/scribblings/new-lambda.ss +++ b/collects/scribblings/new-lambda.ss @@ -7,7 +7,8 @@ (rename new-define define) (rename new-app #%app) (rename *make-keyword-procedure make-keyword-procedure) - keyword-apply) + keyword-apply + procedure-keywords) ;; ---------------------------------------- @@ -103,6 +104,16 @@ (apply list-immutable kws) (apply list-immutable kw-vals) normal-args))))) + + (define (procedure-keywords p) + (cond + [(keyword-procedure? p) + (values (keyword-procedure-required p) + (keyword-procedure-allowed p))] + [(procedure? p) (values null null)] + [else (raise-type-error 'procedure-keywords + "procedure" + p)])) ;; ---------------------------------------- @@ -372,7 +383,7 @@ (mk-id with-kws 'needed-kws - '(kw ...)))))]))))))])) + 'kws))))]))))))])) (define (missing-kw proc . args) (printf "~s\n" args) diff --git a/collects/scribblings/reference/procedures.scrbl b/collects/scribblings/reference/procedures.scrbl index 163594ca45..238898e54f 100644 --- a/collects/scribblings/reference/procedures.scrbl +++ b/collects/scribblings/reference/procedures.scrbl @@ -60,28 +60,24 @@ and @scheme[lst]; otherwise, the @exnraise[exn:fail:contract]. (or/c exact-nonnegative-integer? arity-at-least?)))]{ -Returns information about the number of arguments accepted by -@scheme[proc] when called without keyword arguments. The result -@scheme[_a] is one of the following: +Returns information about the number of by-position arguments accepted +by @scheme[proc]. The result @scheme[_a] is one of the following: @itemize{ @item{An exact non-negative integer, which means that the procedure - always accepts exactly @scheme[_a] arguments.} + accepts @scheme[_a] arguments, only.} @item{A @scheme[arity-at-least] instance, which means that the - procedure takes @scheme[(arity-at-least-value _a)] or more + procedure accepts @scheme[(arity-at-least-value _a)] or more arguments.} @item{A list containing integers and @scheme[arity-at-least] - instances, which means that the procedure takes any number of + instances, which means that the procedure accepts any number of arguments that can match one of the elements of @scheme[_a].} } -If a procedure requires at least one keyword argument, then -@scheme[procedure-arity] returns @scheme['()] for the procedure. - @examples[ (procedure-arity cons) (procedure-arity list) @@ -101,28 +97,25 @@ when no keyword arguments are supplied, @scheme[#f] otherwise. (procedure-arity-includes? display 3) ]} -@defproc[(keyword-procedure-arity [proc procedure?]) +@defproc[(procedure-keywords [proc procedure?]) (values (listof keyword?) (or/c (listof keyword?) - false/c) - (or/c - exact-nonnegative-integer? - arity-at-least? - (listof - (or/c - exact-nonnegative-integer? - arity-at-least?))))]{ + false/c))]{ -Similar to @scheme[keyword-procedure-arity], but for the case -that keywords are supplied to @scheme[proc]. The first result is -a list of keywords (sorted by @scheme[keyword<]) that are -required when applying @scheme[proc]. The second result is a list -of accepted keyword (sorted by @scheme[keyword<]), or @scheme[#f] -to mean that any keyword is accepted. The last result is as for -@scheme[procedure-arity] for the by-position arguments of -@scheme[proc], except that it is not @scheme['()] when keywords -are required.} +Returns information about the keyword arguments required and accepted +by a procedure. The first result is a list of keywords (sorted by +@scheme[keyword<]) that are required when applying @scheme[proc]. The +second result is a list of accepted keywords (sorted by +@scheme[keyword<]), or @scheme[#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. + +@examples[ +(procedure-keywords +) +(procedure-keywords (lambda (#:tag t #:mode m) t)) +(procedure-keywords (lambda (#:tag t #:mode [m #f]) t)) +]} @defproc[(make-keyword-procedure [proc (((listof keyword?) list?) list? . ->* . any)]