Why such implementation of partial in clojure.core -
i stumbled across implementation of partial function in cojure.core. looks this:
(defn partial "takes function f , fewer normal arguments f, , returns fn takes variable number of additional args. when called, returned function calls f args + additional args." {:added "1.0" :static true} ([f] f) ([f arg1] (fn [& args] (apply f arg1 args))) ([f arg1 arg2] (fn [& args] (apply f arg1 arg2 args))) ([f arg1 arg2 arg3] (fn [& args] (apply f arg1 arg2 arg3 args))) ([f arg1 arg2 arg3 & more] (fn [& args] (apply f arg1 arg2 arg3 (concat more args))))) why has several parity options if have one? performance optimisation concat doesn't called in cases?
i mean otherwise, right?
(defn partial ([f] f) ([f & more] (fn [& args] (apply f (concat more args)))) ) i noticed several other functions follow same pattern.
yes, it's performance optimization.
i'ts not not calling concat - it's fact & in argument list requires collection created well. clojure core libraries tend take performance seriously, under assumption basic building blocks of language present in everyone's performance bottleneck.
Comments
Post a Comment