On Wed, May 27, 2009 at 9:57 AM, 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))))))
>

I have to compose in my toolbox, but I do not know Haskell either:

;;COMPOSE-LEFT
;; f1 f2 -> f2 o f1
(define (compose-left . functions)
  (lambda (x)
    (fold-left (lambda (a f) (f a)) x functions)))
;;END

;;COMPOSE-RIGHT
;; f1 f2 -> f1 o f2
(define (compose-right . functions)
  (lambda (x)
    (fold-right (lambda (f a) (f a)) x functions)))
;;END

Reply via email to