added a nullary case to compose
svn: r14697
This commit is contained in:
parent
a1b65fb055
commit
a1d943146b
|
@ -232,7 +232,7 @@
|
||||||
|
|
||||||
(define compose
|
(define compose
|
||||||
(case-lambda
|
(case-lambda
|
||||||
[(f) (if (procedure? f)
|
[(f) (if (procedure? f)
|
||||||
f
|
f
|
||||||
(raise-type-error 'compose "procedure" f))]
|
(raise-type-error 'compose "procedure" f))]
|
||||||
[(f g)
|
[(f g)
|
||||||
|
@ -247,6 +247,7 @@
|
||||||
(call-with-values (lambda () (g a)) f))
|
(call-with-values (lambda () (g a)) f))
|
||||||
(lambda args
|
(lambda args
|
||||||
(call-with-values (lambda () (apply g args)) f)))))]
|
(call-with-values (lambda () (apply g args)) f)))))]
|
||||||
|
[() values]
|
||||||
[(f . more)
|
[(f . more)
|
||||||
(if (procedure? f)
|
(if (procedure? f)
|
||||||
(let ([m (apply compose more)])
|
(let ([m (apply compose more)])
|
||||||
|
|
|
@ -38,7 +38,8 @@ Returns a procedure that composes the given functions, applying the
|
||||||
last @scheme[proc] first and the first @scheme[proc] last. The
|
last @scheme[proc] first and the first @scheme[proc] last. The
|
||||||
composed functions can consume and produce any number of values, as
|
composed functions can consume and produce any number of values, as
|
||||||
long as each function produces as many values as the preceding
|
long as each function produces as many values as the preceding
|
||||||
function consumes.
|
function consumes. When no @scheme[proc] arguments are given, the
|
||||||
|
result is @scheme[values].
|
||||||
|
|
||||||
@mz-examples[
|
@mz-examples[
|
||||||
((compose - sqrt) 10)
|
((compose - sqrt) 10)
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
(test 'hi (compose (case-lambda [(x) 'bye][(y z) 'hi]) (lambda () (values 1 2))))
|
(test 'hi (compose (case-lambda [(x) 'bye][(y z) 'hi]) (lambda () (values 1 2))))
|
||||||
(test 'ok (compose (lambda () 'ok) (lambda () (values))))
|
(test 'ok (compose (lambda () 'ok) (lambda () (values))))
|
||||||
(test 'ok (compose (lambda () 'ok) (lambda (w) (values))) 5)
|
(test 'ok (compose (lambda () 'ok) (lambda (w) (values))) 5)
|
||||||
|
(test 0 (compose) 0)
|
||||||
(test-values '(1 2 3) (lambda () ((compose (lambda (x) (values x (add1 x) (+ x 2))) (lambda (y) y)) 1)))
|
(test-values '(1 2 3) (lambda () ((compose (lambda (x) (values x (add1 x) (+ x 2))) (lambda (y) y)) 1)))
|
||||||
|
|
||||||
(err/rt-test (compose 5))
|
(err/rt-test (compose 5))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user