As it turns out you shouldn't listen to me that much. I messed up completely
with my previous post „Pointfree vs. Pointless“. As Chouser points
out: My claims about
comp creating classes are totally wrong.
partial actually do. It takes a function and some arguments and
returns another function, which when called appends its arguments to the given
ones and passes everything on to the given function. So this
(let [part-f (partial f :a :b)] (part-f :c :d))
is basically equivalent to
(f :a :b :c :d)
Another way to achieve this, is
(let [sharp-f #(f :a :b %1 %2)] (sharp-f :c :d))
#() reader macro can be used to implement
(defn partial [f & args] #(apply f (concat args %&)))
Question: What is the difference between
part-f does not create a new class while
The definition of
partial creates actually two classes: one for
itself and one for the returned function. However, the second class is always
the same! For all calls to
partial! So it actually does not create a new
class when it's called, but only an instance of the second class.
#() version on the other hand is actually a reader macro expanding
fn form. This actually does create a new class each time it is used!
#()s create five new classes, while five
partials create only five
instances of the same class.
Be humble. Understand before you start blogging.
Published by Meikel Brandmeyer on .