[Prev][Next][Index][Thread]

Re: small Q



Rob Warnock <rpw3@rigden.engr.sgi.com> wrote:
>| > In fact, it occurs to me that a nice extension to the language would be
>| > to allow more than two procedures in call-with-values... pipeline...
>
>In MzScheme (or anything with "let*-values"), you can do:
>
>       (let*-values (((a b c) (foo))
>                     ((d e) (bar a b c))
>                     ((f g h) (baz d e)))
>         ...use f,g,h... )

And if you really want to, with a Scheme that supports define-syntax you can
set up something even more explicitly pipeline-ish:

        (define-syntax call-pipe
          (syntax-rules ()
            ((_ th) (th))
            ((_ th proc0 proc1 ...)
             (call-with-values th
               (lambda args
                 (call-pipe (lambda () (apply proc0 args)) proc1 ...))))))

        > (call-pipe (lambda () 1) add1 add1))
        3
        > (define f (lambda (x y) (values (add1 x) (sub1 y))))
        > (define g (lambda (x y) (list x y)))
        > (call-pipe (lambda (x) (values 0 0)) f g)
        (1 -1)

Is it actually useful?  Maybe...

best,
jmj
-- 
	( jordan m johnson : jorjohns @ indiana.edu : (just some guy) )
	( If I were a bug, I would want to be a true Renaissance bug. )



References: