This is a version I found by searching my emails... I haven't used it
in a while, but I think this might be the latest.

 (define-syntax compose
   (syntax-rules ()
     ((_) (lambda a (apply values a)))
     ((_ p p* ...) (lambda a (call-with-values (lambda () (apply p a))
(compose p* ...))))))

The multiple values stuff (whose syntax takes up the bulk of the code)
isn't crucial - just for generality.

In this case your version might be better because you only create two closures.

BTW I usually call this "o" rather than "compose" to keep its uses
looking short.

On Wed, May 27, 2009 at 5:57 PM, Derick Eddington
<[email protected]> wrote:
> On Wed, 2009-05-27 at 17:28 +1000, Ramana Kumar wrote:
>> BTW I also wrote a compose macro which behaves similarly to Haskell's
>> ".", i.e. you can write in "point-free style". I can post it if you
>> want (you can probably just write one yourself). It would fit well
>> with such tools as curry and cut.
>
> My compose from my (xitomatl control) library is:
>
>  (define (compose . procs)
>    (lambda args
>      (let loop ((procs (reverse procs)) (args args))
>        (if (null? procs)
>          (apply values args)
>          (let-values ((vals (apply (car procs) args)))
>            (loop (cdr procs) vals))))))
>
> Is your's significantly different?  If so, I'd like to see it and to
> know how the difference is utilized.  (I'm not very familiar with
> Haskell.)
>
> --
> : Derick
> ----------------------------------------------------------------
>
>

Reply via email to