[racket-dev] Expansion of optional arguments in lambda

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Sun Feb 24 13:49:04 EST 2013

Scratch that, didn't look very deeply at your solution.
-Ian
----- Original Message -----
From: J. Ian Johnson <ianj at ccs.neu.edu>
To: Eric Dobson <eric.n.dobson at gmail.com>
Cc: dev <dev at racket-lang.org>
Sent: Sun, 24 Feb 2013 13:46:14 -0500 (EST)
Subject: Re: [racket-dev] Expansion of optional arguments in lambda

My guess would be code explosion.
-Ian
----- Original Message -----
From: Eric Dobson <eric.n.dobson at gmail.com>
To: dev <dev at racket-lang.org>
Sent: Sun, 24 Feb 2013 12:51:12 -0500 (EST)
Subject: [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)))

_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev


Posted on the dev mailing list.