On Thu, Feb 18, 2010 at 3:36 PM, Richard Newman <holyg...@gmail.com> wrote: > 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))
What to do if we don't know which of the equation variables are unknowns? Let's say that the user may choose whether to input "Rent" and "Sell", or "Rent" and "opportunityCost". I can imagine writing some code like this: (defn opportunity-cost [opportunity-cost-in rent-in sell-in] (if (nil? opportunity-cost-in) (- rent-in sell-in) opportunity-cost-in)) (defn rent [opportunity-cost-in rent-in sell-in] (if (nil? rent-in) ...) (defn sell [opportunity-cost-in rent-in sell-in] (if (nil? sell-in) ...) but complexity of such expressions quickly grows as dependencies between variables become more complex. Is there any technique/framework for handling such calculations automatically? I have a vague impression that this is what logic programming languages are about. How would one implement such calculations in Clojure? Going further, what to do if the equation is underspecified (for example, if the user has only input "Rent") and we want to do something more useful than just fail. This would require us to do the calculations symbolically. Can Clojure help here somehow? What would be a minimal CAS framework in Clojure? -Andrzej -- 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