www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 1bc9be132ca25f77db391391430e27257c16b9cb
parent e22aff53f3b287f006df54ef49172f24e7456deb
Author: AlexKnauth <alexander@knauth.org>
Date:   Tue, 21 Apr 2015 18:36:24 -0400

add docs for kw-hash

Diffstat:
Akw-utils/docs/kw-hash.scrbl | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mkw-utils/docs/kw-utils.scrbl | 2++
Mkw-utils/kw-hash.rkt | 2++
3 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/kw-utils/docs/kw-hash.scrbl b/kw-utils/docs/kw-hash.scrbl @@ -0,0 +1,57 @@ +#lang scribble/manual +@(require scribble/eval + (for-label kw-utils/kw-hash + kw-utils/kw-hash-lambda + racket/base + racket/contract/base + racket/math + )) + +@title[#:tag "kw-hash.scrbl"]{kw-hash} + +@section{kw-hash-lambda} + +@defmodule[kw-utils/kw-hash-lambda] + +@defform[(kw-hash-lambda formals #:kws kw-hash-id body-expr ...+)]{ +roughly equivalent to +@(racketblock + (keyword-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) +]} + +@section{kw-hash} + +@defmodule[kw-utils/kw-hash] + +@defproc[(apply/kw-hash [proc procedure?] [kw-hash (hash/c keyword? any/c)] [v any/c] ... [lst list?]) + any]{ +like @racket[keyword-apply], but instead of taking the keywords and keyword +arguments as separate lists, @racket[apply/kw-hash] takes them in a hash-table. + +Based on @url["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) '()) +]} + +@defproc[(app/kw-hash [proc procedure?] [kw-hash (hash/c keyword? any/c)] [v any/c] ...) + any]{ +like @racket[apply/kw-hash], but doesn't take a list argument at the end. +} + +@defproc[(make-kw-hash [#:<kw> kw-arg any/c] ...) (hash/c keyword? any/c)]{ +returns a hash-table containing the given keyword arguments. +} + diff --git a/kw-utils/docs/kw-utils.scrbl b/kw-utils/docs/kw-utils.scrbl @@ -14,3 +14,5 @@ source code: @url["https://github.com/AlexKnauth/kw-utils"] @include-section[(lib "kw-utils/docs/kw-map.scrbl")] +@include-section[(lib "kw-utils/docs/kw-hash.scrbl")] + diff --git a/kw-utils/kw-hash.rkt b/kw-utils/kw-hash.rkt @@ -13,6 +13,8 @@ (module+ test (require rackunit racket/math)) +;; Based on https://gist.github.com/Metaxal/578b473bc48886f81123 + ;; (apply/kw-hash proc kw-hash arg ... rst-args) (define apply/kw-hash (keyword-lambda (kws kw-args proc kw-hash . other-args)