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)
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?
(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))
> (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?
(define (procedure-reduce-arity+keywords proc a) (procedure-reduce-keyword-arity proc (arity+keywords-arity a) (arity+keywords-required-kws a) (arity+keywords-allowed-kws a)))
> (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)
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?)
procedure
(procedure-arity+keywords-matches? proc n kws) → boolean? proc : procedure? n : natural-number/c kws : (listof keyword?)
procedure
(procedure-arity+keywords-matches?/c n kws) → flat-contract?
n : natural-number/c kws : (listof keyword?)
procedure
(arity+keywords-includes? a1 a2) → boolean?
a1 : arity+keywords? a2 : arity+keywords?
procedure
(arity+keywords-combine/or arity+kws ...) → arity+keywords?
arity+kws : arity+keywords?
> (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?
> (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?
> (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?