<div dir="ltr"><div><div>The process of lambda dropping can also solve your problem.<br><br></div>In essence, make f2 to fx local function definitions inside f1. This eliminates the need for the-data to be an explicit parameter given that f2 through fx would be within the lexical scope of the-data. This assumes, of course, that f2 through fx are not called by other functions in your program.<br>
<br></div>Marco<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 19, 2013 at 12:23 PM, Ben Duan <span dir="ltr"><<a href="mailto:yfefyf@gmail.com" target="_blank">yfefyf@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Scenario: A piece of data is determined in the first function `f1', but is only processed in a sub-sub-sub-
function `fx'.</div>
<div><br></div><div>One way is to use pass `the-data' as arguments from `f1' through `f2' all the way down to `fx':</div>
<div><br></div><div><div><font face="courier new, monospace"> (define f1 (the-data
)</font></div><div><font face="courier new, monospace">
</font></div><div><font face="courier new, monospace"> (f2 the-data
)</font></div>
<div><font face="courier new, monospace">
)</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> (define f2 (the-data
)</font></div><div><font face="courier new, monospace">
</font></div>
<div><font face="courier new, monospace"> (f3 the-data
)</font></div><div><font face="courier new, monospace">
)</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">
</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> (define fx (the-data
)</font></div><div><font face="courier new, monospace">
the-data
)</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="arial, helvetica, sans-serif">But in the above way, the body of `f2', `f3', `f4'</font><span style="font-family:arial,helvetica,sans-serif"> and so on doesn't use `the-data'. It is only passed to the next function. And I still have to add the argument `the-data'.</span></div>
<div><span style="font-family:arial,helvetica,sans-serif"><br></span></div><div><span style="font-family:arial,helvetica,sans-serif">Another way is to use `set!':</span></div><div><br></div><div><font face="courier new, monospace"> (define the-data
)</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> (define f1 (the-data
)</font></div><div><font face="courier new, monospace">
</font></div><div><font face="courier new, monospace"> (set! the-data
)</font></div>
<div><font face="courier new, monospace">
</font></div><div><font face="courier new, monospace"> (f2
)</font></div><div><font face="courier new, monospace">
)</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"> (define f2 (
)</font></div><div><font face="courier new, monospace"> </font><span style="font-family:'courier new',monospace">
</span></div><div><font face="courier new, monospace"> (f3 </font><span style="font-family:'courier new',monospace">
)</span></div>
<div><font face="courier new, monospace">
)</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">
</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"> (define fx (
)</font></div><div><font face="courier new, monospace">
the-data
)</font></div></div><div><br></div><div><font face="arial, helvetica, sans-serif">But in this way, the benefits of being functional are lost. For example there will be some problems writing tests for these functions.</font></div>
<div><br></div><div><font face="arial, helvetica, sans-serif">My question is, which way is better? Or are there other ways to solve this problem?</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div>
<div><font face="arial, helvetica, sans-serif">Thanks,</font></div><div><font face="arial, helvetica, sans-serif">Ben</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">P.S. This question is not about Racket. It's just a beginner's question about how to program. Please let me know if it's not appropriate to ask this kind of questions here. Thank you.</font></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><br clear="all"><br>-- <br><br>Cheers,<br><br>Marco<br><br>Have a΄¨)<br>Έ.·΄Έ.·*΄¨) Έ.·*¨)<br>(Έ.·΄ (Έ.·΄ * wonderful day! :)
</div>