On this page:
1.1 Keyword Rest Arguments
lambda/  kwrest
case-lambda/  kwrest
1.2 Grouping All Keywords into a Hash Table
1.2.1 kw-hash-lambda
kw-hash-lambda
kw-hash-case-lambda
1.2.2 Applying functions with keywords from a hash
apply/  kw-hash
app/  kw-hash
make-kw-hash
1.2.3 Function contracts with kw-hash
kw-hash->
8.12

1 Keywords in Hash Tables🔗ℹ

1.1 Keyword Rest Arguments🔗ℹ

 (require kw-utils/lambda-kwrest) package: kw-utils

syntax

(lambda/kwrest (single-param ...) rest-param ... body ...)

 
single-param = id
  | [id default-expr]
  | keyword id
  | keyword [id default-expr]
     
rest-param = #:rest id
  | #:kwrest id
Produces a procedure that may accept all keywords if #:kwrest is provided.

Examples:
> (require kw-utils/lambda-kwrest)
> (define proc
    (lambda/kwrest () #:rest positional-rest #:kwrest keyword-rest
      (list positional-rest keyword-rest)))
> (proc #:a 'a #:b 'b 0 1 2)

'((0 1 2) #hasheq((#:a . a) (#:b . b)))

syntax

(case-lambda/kwrest [(single-param ...) rest-param ... body ...] ...)

 
single-param = id
  | [id default-expr]
  | keyword id
  | keyword [id default-expr]
     
rest-param = #:rest id
  | #:kwrest id
Produces a procedure that may accept all keywords if #:kwrest is provided.

Examples:
> (require kw-utils/lambda-kwrest)
> (define proc
    (case-lambda/kwrest
      [() #:rest positional-rest #:kwrest keyword-rest
       (list positional-rest keyword-rest)]))
> (proc #:a 'a #:b 'b 0 1 2)

'((0 1 2) #hasheq((#:a . a) (#:b . b)))

1.2 Grouping All Keywords into a Hash Table🔗ℹ

1.2.1 kw-hash-lambda🔗ℹ

 (require kw-utils/kw-hash-lambda) package: kw-utils

syntax

(kw-hash-lambda formals #:kws kw-hash-id body-expr ...+)

roughly equivalent to
(kw-lists-lambda kws kw-args formals
  (let ([kw-hash-id (keyword-apply make-kw-hash kws kw-args '())])
    body ...))

Examples:
> (require kw-utils/kw-hash-lambda)
> (define proc
    (kw-hash-lambda rest-args #:kws kw-hash
      (list rest-args kw-hash)))
> (proc 0 1 2 #:a 'a #:b 'b)

'((0 1 2) #hash((#:a . a) (#:b . b)))

syntax

(kw-hash-case-lambda #:kws kw-hash-id [formals body-expr ...+] ...)

roughly equivalent to
(kw-lists-case-lambda kws kw-args
  [formals
   (let ([kw-hash-id (keyword-apply make-kw-hash kws kw-args '())])
     body ...)]
  ...)

Examples:
> (require kw-utils/kw-hash-lambda)
> (define proc
    (kw-hash-case-lambda #:kws kw-hash
      [(a)
       (list a kw-hash)]
      [(a b)
       (list a b kw-hash)]))
> (proc 0 #:a 'a #:b 'b)

'(0 #hash((#:a . a) (#:b . b)))

> (proc 0 1 #:a 'a #:b 'b)

'(0 1 #hash((#:a . a) (#:b . b)))

1.2.2 Applying functions with keywords from a hash🔗ℹ

 (require kw-utils/kw-hash) package: kw-utils

procedure

(apply/kw-hash proc kw-hash v ... lst)  any

  proc : procedure?
  kw-hash : (hash/c keyword? any/c)
  v : any/c
  lst : list?
like keyword-apply, but instead of taking the keywords and keyword arguments as separate lists, apply/kw-hash takes them in a hash-table.

Based on https://gist.github.com/Metaxal/578b473bc48886f81123.

Examples:
> (require kw-utils/kw-hash racket/math)
> (define (kinetic-energy #:m m #:v v)
    (* 1/2 m (sqr v)))
> (apply/kw-hash kinetic-energy (hash '#:m 2 '#:v 1) '())

1

procedure

(app/kw-hash proc kw-hash v ...)  any

  proc : procedure?
  kw-hash : (hash/c keyword? any/c)
  v : any/c
like apply/kw-hash, but doesn’t take a list argument at the end.

procedure

(make-kw-hash #:<kw> kw-arg ...)  (hash/c keyword? any/c)

  kw-arg : any/c
returns a hash-table containing the given keyword arguments.

1.2.3 Function contracts with kw-hash🔗ℹ

 (require kw-utils/kw-hash/contract) package: kw-utils

syntax

(kw-hash-> [arg/c ...] #:kws kw-hash/c any)

(kw-hash-> [arg/c ...] #:rest rest/c #:kws kw-hash/c any)
Produces a contract for functions that can accept arbitrary keyword arguments. The contract puts the keywords in a hash table and checks that against the kw-hash/c contract.