[racket] Replacing lambdas with defines

From: David Janke (david at thejamesriver.com)
Date: Fri Jun 8 11:37:09 EDT 2012

Since the inner-most lambda block references the list ("l"), aren't the
nested lambda's the cleanest implementation? Otherwise, you would have to
use currying, which looks like it would add complexity (based on a random
article i just found, here
http://www.engr.uconn.edu/~jeffm/Papers/curry.html)

The only other way would be to completely refactor out the map, right?


On Fri, Jun 8, 2012 at 10:25 AM, Ashok Bakthavathsalam
<ashokb at kggroup.com>wrote:

> Below, I have enclosed the code from Rosetta for generating Permutations.
> Can someone show me how to replace nested lambdas with defines?
> Thanks,
>
> (define (insert l n e)
>
>
>   (if (= 0 n)
>
>
>       (cons e l)
>
>
>       (cons (car l)
>
>
>             (insert (cdr l) (- n 1) e))))
>
>
>
> (define (seq start end)
>
>
>   (if (= start end)
>
>
>       (list end)
>
>       (cons start (seq (+ start 1) end))))
>
>
>
> (define (permute l)
>
>
>   (if (null? l)
>
>
>       '(())
>
>
>       (apply append (map (lambda (p)
>
>
>                            (map (lambda (n)
>
>
>                                   (insert p n (car l)))
>
>
>                                 (seq 0 (length p))))
>
>
>                          (permute (cdr l))))))
>
>
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120608/105d4066/attachment.html>

Posted on the users mailing list.