For the method tax_deductible_expenses to run it ends up requiring 19

user defined values. That's a whole lot of arguments to pass into a
function. Obviously I could wrap them up in a StructMap but then I get
expressions like (+ 1 (args :B)) which doesn't seem much better than
(+1 (B)).

Pass them in as a map, and destructure at the start of the function:

  (defn tax-deductible-expenses [{:keys [management-fee
                                         tenant-finding-fee ...]}]
    ...)

The issue I'm really trying to put my finger on is - these arguments
really and truly are 'constants' within the context of the calculator.
But they are constants whose values are not known as compile time but
rather are known at run time.

That they're "constant" does not mean that you shouldn't pass them as arguments to your functions.

Most values obtained from users or config files are such "run-time constants". Heck, many values in most programs are -- "HTTP listener port", "log file location", etc.

You still invoke your HTTP server with a :port argument.

Indeed, the more fixed values you have, the less likely it is that you should define a var for each. Maybe one var containing a map, but I'd still pass the map around rather than having each function implicitly refer to it. It makes testing easier.


Does Clojure have a way to express a
'late bound' constant or is the 'right' solution to pass around 19+
arguments to functions or passing around StructMaps or making
everything into thunks?

The reason you pass them around as arguments is so that the behavior of your functions is precisely determined *only* by its arguments -- they are pure.

That means that you can memoize them, easily write tests for them, have them work correctly when part of a lazy sequence (which will often be evaluated outside the scope of your bindings), etc.

For example: how would you compare the tax-deductible-expenses of two clients? You'd need to invoke the function twice, with a huge nest of bindings around each call. Much better would be to store the appropriate values in two maps, then say

  (< (tax-deductible-expenses 0 john-data)
     (tax-deductible-expenses 0 bill-data))

-R


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

Reply via email to