Hey, here's a hacked together curry function that does it somewhat
like haskell, in pseudo-code. Can you guys help me correct it?

(defn curry [f & args1]
  (cond (= (arity f ) (count args)) (apply f args1)
           (fixed? (arity f) (fn [& args2] (curry (apply partial f
args1) args2)
           (= :end (last args1)) (apply f (pop args1))))

I don't know if apply partial will work, and the arity and function
was pulled out of a hat. I'll get it working tonight.

But this should let you do

(((curry + 4 5 6)  6 8 10) 1 1 :end) => 41

or

(def add5 (curry #(+ %1 %2) 5))

(add5 6) => 11


I don't like the :end hack, but currying doesn't work with variable
arity functions otherwise.


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to