<div dir="ltr">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.<div>
<br></div><div><div>#lang racket</div><div><br></div><div>(define f</div><div>  (case-lambda </div><div>    (() (f 1))</div><div>    ((a) (f a (+ 3 a)))</div><div>    ((a b) (f a b (* a b)))</div><div>    ((a b c) (f a b c (- a (/ c b))))</div>
<div>    ((a b c d) (+ a b c d))))</div><div><br></div><div>(define (g (a 1) (b (+ 3 a)) (c (* a b)) (d (- a (/ c b))))</div><div>  (+ a b c d))</div><div><br></div><div>(define N 1000000)</div><div><br></div><div>(collect-garbage)</div>
<div>(collect-garbage)</div><div>(time</div><div>  (for ((i (in-range N)))</div><div>    (f i)))</div><div><br></div><div>(collect-garbage)</div><div>(collect-garbage)</div><div>(time</div><div>  (for ((i (in-range N)))</div>
<div>    (g i)))</div><div><br></div><div><br></div><div>(collect-garbage)</div><div>(collect-garbage)</div><div>(time</div><div>  (for ((i (in-range N)))</div><div>    (f i)))</div><div><br></div><div>(collect-garbage)</div>
<div>(collect-garbage)</div><div>(time</div><div>  (for ((i (in-range N)))</div><div>    (g i)))</div></div></div>