> And it's implementation is not that trivial: Excellent point! I've modified --> so that now it's even more versatile and only evaluates the functions once.
Now this is possible: user=> (--> 1 (+ 1 _) (do (println "sideeffect!") _) (hash-map :a _ :b (+ 3 _)) :b) sideeffect! 5 It now requires an additional replace-all function (a modified replace): (defn replace-all [smap coll] (if (vector? coll) (reduce (fn [v i] (if-let [e (find smap (nth v i))] (assoc v i (val e)) v )) coll (range (count coll)) ) (map #(if-let [e (find smap %)] (val e) (if (seq? %) (replace-all smap %) % ) ) coll ) ) ) (defmacro --> ([x] x) ([x form] (if (seq? form) `(let [~'_ ~x] ~form) (list form x) ) ) ([x form & more] ; cache the result of the first form (let [_ `(--> ~x ~form)] `(--> ~_ ~...@more) ) ) ) - Greg On Jul 6, 2010, at 11:55 AM, Meikel Brandmeyer wrote: > Hi, > > On Jul 6, 5:47 pm, Stuart Halloway <stuart.hallo...@gmail.com> wrote: > >> There is not general agreement that something like --> is more readable. (I >> for one disagree, at least so far.) > > And it's implementation is not that trivial: > > user=> (macroexpand '(--> (launch-rockets-if-called-twice) > (call :first _ :second _))) > (call :first (launch-rockets-if-called-twice) :second (launch-rockets- > if-called-twice)) > > Maybe there is just not much need for such a macro (at least for me, > don't for the generality of users). 99% of my use cases can be handled > with -> or ->> (or a combination there of). > > Sincerely > Meikel > > -- > 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 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