News for hackers. Stuff that matters.
Re:Clojure or: How I Learned to Stop Worrying and Love the P... by fogus on Tuesday August 31, 2010 @03:29PM (#1650597)
If you don't want the weight of pulling in Incanter libs, here's a pair of functions for infix ops* in Clojure:

    (def && #(and % %2))
    (def || #(or  % %2))
    
    (def *rank* (zipmap [- + * / < > && || =] 
                        (iterate inc 1)))
        
    (defn- infix* 
      [[a b & [c d e & m]]]
      (cond
       (vector? a) (recur (list* (infix* a) b c d e m))
       (vector? c) (recur (list* a b (infix* c) d e m))
       (ifn? b) (if (and d (< (*rank* b 0) (*rank* d 0)))
                 (recur (list a b (infix* (list* c d e m))))
                 (recur (list* (b a c) d e m)))
       :else a))
        
    (defn infix [& args]
      (infix* args))

* from my unfix lib http://fogus.me/fun/unfix

There are no comments on this comment yet.