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 
<a href="http://www.engr.uconn.edu/~jeffm/Papers/curry.html">http://www.engr.uconn.edu/~jeffm/Papers/curry.html</a>)<div><br></div><div>The only other way would be to completely refactor out the map, right?</div><div><br>
<br><div class="gmail_quote">On Fri, Jun 8, 2012 at 10:25 AM, Ashok Bakthavathsalam <span dir="ltr">&lt;<a href="mailto:ashokb@kggroup.com" target="_blank">ashokb@kggroup.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Below, I have enclosed the code from Rosetta for generating Permutations. Can someone show me how to replace nested lambdas with defines? <div>Thanks,<br><div><br></div><div><pre style="white-space:pre-wrap;color:rgb(34,34,34);font-family:monospace,&#39;Courier New&#39;;padding:1em;border:1px dashed rgb(47,111,171);background-color:rgb(249,249,249);line-height:1.3em;overflow:auto;font-size:13px">
<span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">define</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span>insert <span style="font-weight:bold;color:rgb(0,0,255)">l</span> n <span style="font-weight:bold;color:rgb(0,0,255)">e</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


  <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">if</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span>= <span style="font-weight:bold;color:rgb(0,153,153)">0</span> n<span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


      <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">cons</span> <span style="font-weight:bold;color:rgb(0,0,255)">e</span> <span style="font-weight:bold;color:rgb(0,0,255)">l</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


      <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">cons</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">car</span> <span style="font-weight:bold;color:rgb(0,0,255)">l</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span> <br>


            <span style="font-weight:bold;color:rgb(0,153,0)">(</span>insert <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">cdr</span> <span style="font-weight:bold;color:rgb(0,0,255)">l</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span>- n <span style="font-weight:bold;color:rgb(0,153,153)">1</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span> <span style="font-weight:bold;color:rgb(0,0,255)">e</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


 <br><span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">define</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span>seq start end<span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


  <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">if</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span>= start end<span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


      <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">list</span> end<span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>
      <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">cons</span> start <span style="font-weight:bold;color:rgb(0,153,0)">(</span>seq <span style="font-weight:bold;color:rgb(0,153,0)">(</span>+ start <span style="font-weight:bold;color:rgb(0,153,153)">1</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span> end<span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


 <br><span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">define</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span>permute <span style="font-weight:bold;color:rgb(0,0,255)">l</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


  <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">if</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">null?</span> <span style="font-weight:bold;color:rgb(0,0,255)">l</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


      &#39;<span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


      <span style="font-weight:bold;color:rgb(0,153,0)">(</span>apply <span style="font-weight:bold;color:rgb(0,0,255)">append</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">map</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">lambda</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span>p<span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


                           <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">map</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">lambda</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span>n<span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


                                  <span style="font-weight:bold;color:rgb(0,153,0)">(</span>insert p n <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">car</span> <span style="font-weight:bold;color:rgb(0,0,255)">l</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


                                <span style="font-weight:bold;color:rgb(0,153,0)">(</span>seq <span style="font-weight:bold;color:rgb(0,153,153)">0</span> <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">length</span> p<span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><br>


                         <span style="font-weight:bold;color:rgb(0,153,0)">(</span>permute <span style="font-weight:bold;color:rgb(0,153,0)">(</span><span style="font-weight:bold;color:rgb(0,0,255)">cdr</span> <span style="font-weight:bold;color:rgb(0,0,255)">l</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span><span style="font-weight:bold;color:rgb(0,153,0)">)</span></pre>

</div></div>
<br>____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div>