[racket] Replacing lambdas with defines

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jun 14 10:22:28 EDT 2012

On Friday, Ashok Bakthavathsalam wrote:
> Below, I have enclosed the code from Rosetta for generating
> Permutations. Can someone show me how to replace nested lambdas with
> defines?  Thanks,
> [...]

To clarify what I said on S.O., my comment was a reply to someone
saying that some lambda expression can't be made to use the shorthand.
What I meant is that there's no real need for an anonymous `lambda'
form, since you can always turn them into definitions -- just replace

  (lambda (x y) (whatever))


  (let ()
    (define (foo x y) (whatever))

This is obviously not shorter and it won't read better -- so in
practical terms it's much better to just use `lambda'.

BTW, usually when people try to get rid of such "nested lambdas", the
motivation is to avoid some cost of generating a function at runtime.
If that's the case, then JFYI there is no such cost -- it's possible
to compile these functions ahead of time just like any other code,
there's no repeated code generation that happens in your example.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.