added a nullary case to compose

svn: r14697
This commit is contained in:
Eli Barzilay 2009-05-03 20:41:37 +00:00
parent a1b65fb055
commit a1d943146b
3 changed files with 5 additions and 2 deletions

View File

@ -232,7 +232,7 @@
(define compose
(case-lambda
[(f) (if (procedure? f)
[(f) (if (procedure? f)
f
(raise-type-error 'compose "procedure" f))]
[(f g)
@ -247,6 +247,7 @@
(call-with-values (lambda () (g a)) f))
(lambda args
(call-with-values (lambda () (apply g args)) f)))))]
[() values]
[(f . more)
(if (procedure? f)
(let ([m (apply compose more)])

View File

@ -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
composed functions can consume and produce any number of values, as
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[
((compose - sqrt) 10)

View File

@ -14,6 +14,7 @@
(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 (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)))
(err/rt-test (compose 5))