7.7
2 kw-hash
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)))
2.2 kw-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.
2.3 kw-hash contracts
(require kw-utils/kw-hash/contract) | package: kw-utils |
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.