On 19 July 2010 20:42, Brenton <bashw...@gmail.com> wrote: > Hi Paul, > > Pure functions have two properties: they cannot produce side effects > and the return value is a function (in the mathematical sense) of its > arguments and nothing else. There are two corresponding questions that > you can ask when looking at a function to determine if it is pure. > > 1) When I call this function with the same arguments, do I always get > the same result? > 2) Is it true that the only reason you would ever call this function > is to obtain the value that is returned from it? > > If the answer to both of these questions is Yes, then you are looking > at a pure function.
So back to my example: (def forty-two 42) (defn func [] (* forty-two forty-two)) (defn other-func [] (binding [forty-two 6] (func))) "func" is impure, and "other-func" is pure. It's really nothing to do with whether the "binding" keyword is used in the function... I think I took the sentence from the book too literally. [snip] > The earmuffs are the idiomatic Clojure way of indicating that > something is intended to be dynamically bound. The caller must bind > *something* to a value or this code will not work. This is what > "Programming Clojure" means when it states: "Functions that use > dynamic bindings are not pure functions..", it is not referring to > functions which use binding internally (as in your example) but to > functions which depend on values that are dynamically bound outside of > said function. > [snip] Pefect, thank you. :) -- Paul Richards @pauldoo -- 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