lambda supports optional arguments, and does this by expanding out into a core form that has flag arguments for if each argument is supplied. This is tricky to type in TR and so I was investigating why it did it this way. I did a micro benchmark on another method of expansion and it was 60% faster. Is there a reason that racket does it the current way that I am missing.
#lang racket (define f (case-lambda (() (f 1)) ((a) (f a (+ 3 a))) ((a b) (f a b (* a b))) ((a b c) (f a b c (- a (/ c b)))) ((a b c d) (+ a b c d)))) (define (g (a 1) (b (+ 3 a)) (c (* a b)) (d (- a (/ c b)))) (+ a b c d)) (define N 1000000) (collect-garbage) (collect-garbage) (time (for ((i (in-range N))) (f i))) (collect-garbage) (collect-garbage) (time (for ((i (in-range N))) (g i))) (collect-garbage) (collect-garbage) (time (for ((i (in-range N))) (f i))) (collect-garbage) (collect-garbage) (time (for ((i (in-range N))) (g i)))
_________________________ Racket Developers list: http://lists.racket-lang.org/dev