<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>