I don't expect anyone to actually read, rather I was hoping some folks
who know Clojure might just glance at it to get the rhythm of the
math. It's the pattern, not the detail that matters. How should what
is essentially a monster algebra equation be codified in Clojure?
I looked at your PDF.
You express the equations as functions. Turning your equation notation
into function notation -- I'll use Haskell's as an example:
OpportunityCost = Rent - Sell
becomes
opportunityCost r s = r - s
or in Clojure:
(defn opportunity-cost [r s]
(- r s))
Note that the implicit arguments in your equational notation become
explicit arguments in the functional version.
How do I compute r and s? Why, with functions of course! Let's take
Sell as an example.
Sell = HouseSaleProfit0(1 +
RealMonthlyOpportunityCost)^MonthsInBusiness
which becomes
(defn sell [hsp-zero rmoc mib]
(* hsp-zero
(exp (+ 1 rmoc) mib))) ; Assuming exp defined.
Now, assuming that we have Rent, HSP0, RMOC, and MIB calculated (which
follows the same pattern), we compute our OpportunityCost:
(defn -main []
;; TODO: extract user arguments.
;; ...
(let [hsp-zero (...) ; More calculation.
rmoc (...)
mib (...)]
(println "Opportunity Cost: "
(opportunity-cost rent (sell hsp-zero rmoc mib))))
To turn this into your final code, you need only:
* Keep walking through your formulae until you've expressed everything
as functions;
* Grab the nineteen or so "leaf" values you need from the user, and
plug them into your calls.
When you have intermediate values, bind them with let, as I show above.
Note that:
* Each of the functions stands alone, defined in terms of its
arguments, and follows naturally from your equations
* You can compute any intermediate stage, and print them out, log
them, whatever
* There are no global values or bindings
* You can name each intermediate value using let; your main function
can essentially be a sequential set of intermediate calculations, just
like your PDF.
--
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