[racket-dev] Expansion of optional arguments in lambda
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)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20130224/9164140d/attachment.html>