www

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

commit 18bcd9f0f314927f6b618d5821688c5f6cf9e935
parent 4185dd42032fc89e513fe382d11fdc231e198d7e
Author: AlexKnauth <alexander@knauth.org>
Date:   Wed,  1 Apr 2015 21:43:06 -0400

add docs for kw-map

Diffstat:
Akw-utils/docs/kw-map.scrbl | 27+++++++++++++++++++++++++++
Mkw-utils/docs/kw-utils.scrbl | 2++
Mkw-utils/kw-map.rkt | 4++++
3 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/kw-utils/docs/kw-map.scrbl b/kw-utils/docs/kw-map.scrbl @@ -0,0 +1,27 @@ +#lang scribble/manual + +@(require scribble/eval + (for-label kw-utils/kw-map + (rename-in racket/base [map rkt:map]) + racket/math + )) + +@title[#:tag "kw-map.scrbl"]{map with keyword arguments} + +@defmodule[kw-utils/kw-map] + +@defproc[(map [proc procedure?] [lst list?] ... [#:<kw> lst2 list?] ...) list?]{ +like @racket[rkt:map], but accepts keyword arguments as well as positional arguments. + +@examples[ + (require kw-utils/kw-map racket/math) + (map (λ (x) (+ x 1)) '(1 2 3 4)) + (map (λ (#:x x) (+ x 1)) #:x '(1 2 3 4)) + (map (λ (x y) (+ x y)) '(1 2 3 4) '(10 100 1000 10000)) + (map (λ (x #:y y) (+ x y)) '(1 2 3 4) #:y '(10 100 1000 10000)) + (define (KE #:m m #:v v) + (* 1/2 m (sqr v))) + (map KE #:m '(2 2 2 2) #:v '(0 1 2 3)) + (map KE #:m '(0 1 2 3) #:v '(0 1 2 3)) + (map KE #:m '(1 2 1/2 2/9) #:v '(0 1 2 3)) +]} diff --git a/kw-utils/docs/kw-utils.scrbl b/kw-utils/docs/kw-utils.scrbl @@ -12,3 +12,5 @@ source code: @url["https://github.com/AlexKnauth/kw-utils"] @include-section[(lib "kw-utils/docs/arity+keywords.scrbl")] +@include-section[(lib "kw-utils/docs/kw-map.scrbl")] + diff --git a/kw-utils/kw-map.rkt b/kw-utils/kw-map.rkt @@ -31,6 +31,10 @@ define map keyword-apply(f kws kw-args args) module+ test + check-equal? (map (λ (#:x x) {x + 1}) #:x '(1 2 3 4)) + '(2 3 4 5) + check-equal? (map (λ (x #:y y) {x + y}) '(1 2 3 4) #:y '(10 100 1000 10000)) + '(11 102 1003 10004) define (KE #:m m #:v v) {1/2 * m * sqr(v)} check-equal? (map KE #:m '(2 2 2 2) #:v '(0 1 2 3))