On this page:
4.1 Procedure arities with keywords
arity+  keywords
procedure-arity+  keywords
procedure-reduce-arity+  keywords
procedure-reduce-keyword-arity/  sort
arity+  keywords-matches?
procedure-arity+  keywords-matches?
procedure-arity+  keywords-matches?/  c
arity+  keywords-includes?
arity+  keywords-combine/  or
arity+  keywords-combine/  and
4.2 Getting the arity from function arguments syntax
kw-formals->arity+  keywords
kw-formals->arity
kw-formals->required-kws
kw-formals->allowed-kws
7.7

4 arity+keywords

4.1 Procedure arities with keywords

 (require kw-utils/arity+keywords) package: kw-utils

struct

(struct arity+keywords (arity required-kws allowed-kws)
    #:transparent)
  arity : procedure-arity?
  required-kws : (listof keyword?)
  allowed-kws : (or/c (listof keyword?) #f)
represents a procedure’s arity including the keywords required and keywords allowed.

The arity field represents the arity produced by procedure-arity.

The next 2 fields (required-kws and allowed-kws ) represent the 2 values produced by procedure-keywords.

A #f value for allowed-kws means that it accepts all keywords.

The guard procedure also sorts the keyword lists for you.

procedure

(procedure-arity+keywords proc)  arity+keywords?

  proc : procedure?
returns an arity+keywords instance representing the arity and keyword-arity of proc.

It is defined like this:
(define (procedure-arity+keywords proc)
  (define arity (procedure-arity proc))
  (define-values (req-kws allowed-kws)
    (procedure-keywords proc))
  (arity+keywords arity req-kws allowed-kws))

Examples:
> (require kw-utils/arity+keywords)
> (define proc (make-keyword-procedure void))
> (procedure-arity+keywords proc)

(arity+keywords (arity-at-least 0) '() #f)

> (procedure-arity+keywords (procedure-reduce-arity proc 5))

(arity+keywords 5 '() '())

> (procedure-arity+keywords
   (procedure-reduce-keyword-arity/sort proc 3 '(#:kw #:other-kw) '(#:kw #:other-kw #:optional-kw)))

(arity+keywords 3 '(#:kw #:other-kw) '(#:kw #:optional-kw #:other-kw))

procedure

(procedure-reduce-arity+keywords proc    
  arity+kws)  procedure?
  proc : procedure?
  arity+kws : arity+keywords?
like procedure-reduce-arity, except that it accepts an arity+keywords and handles the keyword-arity as well.

It is defined like this:

Examples:
> (require kw-utils/arity+keywords)
> (define proc (make-keyword-procedure void))
> (procedure-arity proc)

(arity-at-least 0)

> (procedure-keywords proc)

'()

#f

> (define proc-with-arity
    (procedure-reduce-arity+keywords
     proc
     (arity+keywords 5 '(#:kw #:other-kw) '(#:kw #:other-kw #:optional-kw))))
> (procedure-arity proc-with-arity)

5

> (procedure-keywords proc-with-arity)

'(#:kw #:other-kw)

'(#:kw #:optional-kw #:other-kw)

procedure

(procedure-reduce-keyword-arity/sort proc    
  arity    
  required-kws    
  allowed-kws)  procedure?
  proc : procedure?
  arity : procedure-arity?
  required-kws : (listof keyword?)
  allowed-kws : (or/c (listof keyword?) #f)
like procedure-reduce-keyword-arity, but without the constraint that the keywords in required-kws or allowed-kws must be sorted.

It is equivalent to (procedure-reduce-arity+keywords proc (arity+keywords arity required-kws allowed-kws)).

procedure

(arity+keywords-matches? arity+kws n kws)  boolean?

  arity+kws : arity+keywords?
  n : natural-number/c
  kws : (listof keyword?)
determines whether the given arity+kws accepts the n by-position arguments and the keywords in kws.

procedure

(procedure-arity+keywords-matches? proc    
  n    
  kws)  boolean?
  proc : procedure?
  n : natural-number/c
  kws : (listof keyword?)

produces a flat contract (also a predicate) that accepts procedures that accept n by-position arguments and accepts the keywords in kws.

procedure

(arity+keywords-includes? a1 a2)  boolean?

  a1 : arity+keywords?
  a2 : arity+keywords?
like arity-includes?, but for arity+keywords instances. But most of the time when when you would use arity-includes?, you really want arity+keywords-matches?.

procedure

(arity+keywords-combine/or arity+kws ...)  arity+keywords?

  arity+kws : arity+keywords?
combines the arity+kwses into one arity+keywords instance in an or-like way.

Examples:
> (require kw-utils/arity+keywords)
> (arity+keywords-combine/or (arity+keywords 1 '(#:a)     '(#:a #:b #:c))
                             (arity+keywords 2 '(#:a #:b) '(#:a #:b #:d)))

(arity+keywords '(1 2) '(#:a) '(#:a #:b #:c #:d))

procedure

(arity+keywords-combine/and arity+kws ...)  arity+keywords?

  arity+kws : arity+keywords?
combines the arity+kwses into one arity+keywords instance in an and-like way.

Examples:
> (require kw-utils/arity+keywords)
> (arity+keywords-combine/and (arity+keywords '(1 2) '(#:a) '(#:a #:b #:c #:d))
                              (arity+keywords '(2 3) '(#:b) '(#:a #:b #:c #:e)))

(arity+keywords 2 '(#:a #:b) '(#:a #:b #:c))

4.2 Getting the arity from function arguments syntax

 (require kw-utils/arity+keywords/syntax)
  package: kw-utils

procedure

(kw-formals->arity+keywords fmls-stx)  arity+keywords?

  fmls-stx : syntax?
Given the args in (lambda args body), returns an arity+keywords value representing the arity and keywords of the function.

Examples:
> (require kw-utils/arity+keywords/syntax)
> (kw-formals->arity+keywords #'())

(arity+keywords 0 '() '())

> (kw-formals->arity+keywords #'(a b c))

(arity+keywords 3 '() '())

> (kw-formals->arity+keywords #'(a b [c 2]))

(arity+keywords '(2 3) '() '())

> (kw-formals->arity+keywords #'(a b . rst))

(arity+keywords (arity-at-least 2) '() '())

> (kw-formals->arity+keywords #'(a #:b b))

(arity+keywords 1 '(#:b) '(#:b))

> (kw-formals->arity+keywords #'(a #:b [b 1]))

(arity+keywords 1 '() '(#:b))

> (kw-formals->arity+keywords #'(#:a a . rst))

(arity+keywords (arity-at-least 0) '(#:a) '(#:a))

procedure

(kw-formals->arity fmls-stx)  normalized-arity?

  fmls-stx : syntax?

procedure

(kw-formals->required-kws fmls-stx)  (listof keyword?)

  fmls-stx : syntax?

procedure

(kw-formals->allowed-kws fmls-stx)  (listof keyword?)

  fmls-stx : syntax?
Like kw-formals->arity+keywords, but just for the positional-argument arity, required keywords, and allowed keywords.