[racket] Use `set!' or not in this scenario?

From: Ben Duan (yfefyf at gmail.com)
Date: Fri Jul 19 12:23:30 EDT 2013

Scenario: A piece of data is determined in the first function `f1', but is
only processed in a sub-sub-sub-… function `fx'.

One way is to use pass `the-data' as arguments from `f1' through `f2' all
the way down to `fx':

    (define f1 (the-data …)
      …
      (f2 the-data …)
      …)

    (define f2 (the-data …)
      …
      (f3 the-data …)
      …)

    …

    (define fx (the-data …)
      … the-data …)

But in the above way, the body of `f2', `f3', `f4' 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'.

Another way is to use `set!':

    (define the-data …)

    (define f1 (the-data …)
      …
      (set! the-data …)
      …
      (f2 …)
      …)

    (define f2 (…)
      …
      (f3 …)
      …)

    …

    (define fx (…)
      … the-data …)

But in this way, the benefits of being functional are lost. For example
there will be some problems writing tests for these functions.

My question is, which way is better? Or are there other ways to solve this
problem?

Thanks,
Ben

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130720/0041925d/attachment.html>

Posted on the users mailing list.