partial.scrbl (1622B)
1 #lang scribble/manual 2 3 @(require scribble/eval 4 (for-label kw-utils/partial 5 racket/base 6 racket/contract/base 7 racket/function 8 )) 9 10 @title{Partial application with keywords} 11 12 @defmodule[kw-utils/partial] 13 14 @defproc*[([(partial [f procedure?] [arg any/c] ... [#:<kw> kw-arg any/c] ...) procedure?] 15 [(partial [#:<kw> kw-arg any/c] ...) procedure?])]{ 16 Similar to @racket[curry], but better thought of as a generalization of 17 @racketidfont{partial} from @racketmodname[rackjure]. Unlike @racket[curry], 18 (but like the @racketmodname[rackjure] version), it does not care about function 19 arity, and so has much simpler behavior, so that 20 @racket[((partial f in-arg ...) out-arg ...)] is equivalent to 21 @racket[(f in-arg ... out-arg ...)] no matter what arity @racket[f] has. 22 It also generalizes this idea to include keyword arguments. 23 @examples[ 24 (require kw-utils/partial) 25 ((partial + 1 2)) 26 ((partial + 1) 2) 27 ((partial +) 1 2) 28 ((partial) + 1 2) 29 (define (KE #:m m #:v v) 30 (* 1/2 m v v)) 31 ((partial KE) #:m 2 #:v 1) 32 ((partial KE #:m 2) #:v 1) 33 ((partial KE #:m 2 #:v 1)) 34 ((partial) KE #:m 2 #:v 1) 35 ((partial #:m 2) KE #:v 1) 36 ]} 37 38 @defproc[(app [f procedure?] [arg any/c] ... [#:<kw> kw-arg any/c] ...) any]{ 39 A procedure for normal function application. 40 @racket[(partial #:<kw> kw-arg ... ...)] is equivalent to 41 @racket[(partial app #:<kw> kw-arg ... ...)]. 42 @examples[ 43 (require kw-utils/partial) 44 (+ 1 2) 45 (app + 1 2) 46 (define (KE #:m m #:v v) 47 (* 1/2 m v v)) 48 (KE #:m 2 #:v 1) 49 (app KE #:m 2 #:v 1) 50 ]} 51