[racket] Y-combinator perfomance

From: Štěpán Němec (stepnem at gmail.com)
Date: Sat Jun 26 05:20:22 EDT 2010


Matthias Felleisen <matthias-1vnkWVZi4QaVc3sceRu5cw at public.gmane.org>
writes:

> CODE: 
>
> #lang racket
>
> (define-syntax U
>   (syntax-rules ()
>     [(_ f) (f f)]))
>
> (define-syntax define/comb
>   (syntax-rules ()
>     [(_ comb name (arg1 arg2) body)
>      (define name 
>        (comb (λ (name) (λ (arg1 arg2) body))))]))
>
> (define (Z f)
>   (U (λ (g) (λ (x y) ((f (U g)) x y)))))
>
> (define/comb Z comb-sum (l t) 
>   (if (empty? l) t (comb-sum (rest l) (+ t (first l)))))
>
> (define (sum l t)
>   (if (empty? l) t (sum (rest l) (+ t (first l)))))
>
> (collect-garbage)(collect-garbage)
> (time (comb-sum (make-list 10000000 1) 0))
>
> (collect-garbage)(collect-garbage)
> (time (sum (make-list 10000000 1) 0))

Why are the `collect-garbage' calls doubled?

    Štěpán



Posted on the users mailing list.