Shouldn't it be like: (definline pred-transform [obj pred tf] `(if (~pred ~obj) ~obj (~tf ~obj))) => (pred-transform 1 #(not (nil? %)) println) 1 => (pred-transform 1 nil? println) 1 nil
On Sat, May 25, 2013 at 2:55 PM, atkaaz <atk...@gmail.com> wrote: > just wondering if obj is a form does it get evaluated twice? > > > On Sat, May 25, 2013 at 2:51 PM, Jim - FooBar(); <jimpil1...@gmail.com>wrote: > >> no need for macros... :) >> >> (definline safe-assoc [m k v] >> `(if (contains? ~m ~k) ~m >> (assoc ~m ~k ~v))) >> >> (definline pred-transform [obj pred tf] >> `(if ~(pred obj) ~obj >> ~(tf obj))) >> >> Jim >> >> >> >> On 25/05/13 12:44, atkaaz wrote: >> >> may I see the macro for the latter, if you decide to go that way ? thx >> >> >> On Sat, May 25, 2013 at 2:24 PM, Steven Degutis <sbdegu...@gmail.com>wrote: >> >>> There are two patterns I find in my code that I'm still unhappy with but >>> I don't know how to clean up. >>> >>> The first is: (if (:attr obj) obj (assoc obj :attr something)) >>> >>> I'm basically saying, give this hash-map an attribute if it doesn't >>> already have it. And just return the thing with an attribute, regardless if >>> I had to add it or not. >>> >>> This version is ugly because it repeats obj three times. I could write >>> my own macro to de-duplicate it, but I avoid doing that when I can because >>> there's usually a better built-in solution that I just don't know about yet. >>> >>> The second is like it: (if (some-test obj) obj (some-transformation >>> obj)) >>> >>> In this one, I just want to return the object, but maybe transform it >>> first. But the reference to obj happens three times! Still feels like it >>> could be cleaned up. >>> >>> Any thoughts on how to clean these up? >>> -- >>> -- >>> 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 >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "Clojure" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to clojure+unsubscr...@googlegroups.com. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> -- >> -- >> 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 >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> >> -- >> -- >> 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 >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.