> As far as I understood, optimizer somehow cannot get the result of `apply`.
> Maybe we should replace `compose` with case-lambda version (for 5-10 args at 
> least)?

Changed to

(define compose
  (case-lambda
    [() identity]
    [(f) (lambda (x) (f1 x))]
    [(f1 f2) (lambda (x) (f1 (f2 x)))]
    [(f1 f2 f3) (lambda (x) (f1 (f2 (f3 x))))]
    [(f . fs) (cond
                [(null? fs) f]
                [else
                 (define rest-f (apply compose fs))
                 (lambda (x) (f (rest-f x)))])]))
(define f-comp (apply compose (list f1 f2 f3)))

Still fast.

If change `compose` to only recurse
(define (compose f . fs) 
  (cond
     [(null? fs) f]
     [else
       (define rest-f (apply compose fs))
       (lambda (x) (f (rest-f x)))]))
then (compose f1 f2 f3) is slow.
But, if manually unroll recursive `compose` and set 
(define f-comp (lambda (x) (f1 ((lambda (x) (f2 (f3 x))) x)))
then again fast.

Now I again don't understand why.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to