On Thu, Mar 10, 2011 at 9:51 AM, faenvie <faen...@googlemail.com> wrote: > references to *opts* are scattered all over my clojure-code > so that many of the functions are impure. this seems like > a smell to me and there are probably cleaner ways to propagate > config-params (keep functions pure) ... what are they ?
There is only one; the only way to get information into a pure function is in its parameters. So you'd have to pass the *opts* object down the call chain to every function that needs it. On the other hand, function purity can be scoped, in a sense. If *opts* is set once, at startup, and does not change after that, then otherwise-pure functions that depend on it are "pure" within the context of a single run of the program, since they will not change their behavior (or change the behavior of anything else) during that run, consistently returning the same value when called with the same arguments. If *opts* is different from one run to the next, it's as though one set of pure functions were used in the one run, and another set of pure functions in the next run. The reason impure functions can be trouble is because they can suffer long-range interactions that screw things up in difficult-to-debug ways. But if *opts* is unchanging after startup there shouldn't be any long-range interactions to trouble you. Of course, the program may misbehave if *opts* is set wrong, but the same would be true if it got passed everywhere as a parameter. Just keep in mind that *opts*, or rather the code that sets it up during startup and whatever influences it (e.g. the set of command-line args), is one more place to check for the causes of bugs. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en