On 22.05.2009, at 11:01, Mark Engelberg wrote: > I was thinking that if you have: > (def a 2) > (def b 3) > (defn f [] a) > > and you set it up with your deftemplate macro where f is the thing > that is parameterized, then if you try to pass in a new value for f, > like: > (fn [] b), it macro expands to > (let [f (fn [] b)] > (def a 2) > (def b 3)) > which clearly doesn't work.
Templates do nothing but symbol remplacement, so if you specify f as a template parameter and pass in (fn [] b) as its value, you get (defn (fn [] b) [] a) If you want to be able to pass in a function object, you'd have to write your template as (deftemplate my-template [function] (def a 2) (def b 3) (def f function)) If you want to redefine the function f given in the template, you'd just write the new definition after the template expansion. > I find it ironic that after years of eschewing objects, I'm > discovering that at the module level, I desperately want something > object-like. You have very much the same problems using objects. You can add and override methods and attributes, but you still have to refer to existing attributes and methods by the names defined in the original class. You also have to be careful not to use these names again for a different purpose. With templates, you have to know the symbols used in specific places in order to be able to refer to them and to avoid overwriting them. The restrictions and conditions are thus very similar. Konrad. --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---