Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Syntax and reader by

A question popped into my head today: Was auto-currying ever on the table for Clojure's design or implementation?

Let's say you have:

(defn add [x y] (+ x y))

(map (add 2) [1 2 3 4 5])

If Clojure auto-curried, that would result in [3 4 5 6 7] but currently it results in an error due to arity mismatch. To me, I feel that behavior would be more productive than an error. So I'm curious about why such a feature was deliberately avoided if it was ever on the table.

4 Answers

+4 votes
selected by
Best answer

I do not know the full answer to this question, but below is a link to a discussion on the Clojure Google group from October 2008, where Rich Hickey responded to a particular suggestion for one way to add currying capability to Clojure.


Rich knew about currying, for certain. How strongly it was considered, I do not know. Anonymous functions and Clojure's #() syntax can do things that currying cannot, albeit taking a few more characters to type it, perhaps. I would not be surprised if there are many other design tradeoffs not mentioned in my message, and not raised in the linked discussion thread.

+5 votes


TL;DR: Clojure was designed to have variadic functions and that is mutually exclusive to currying.

You wouldn't be able to have named (keyword) arguments either if you had currying.

TIL about keyword arguments in Clojure
+3 votes

Another old discussion thread involving Rich Hickey about currying, and a function appl that does partial application (I guess the name "appl" is kind of a joke in that it is only part of the word "application"): https://groups.google.com/forum/#!searchin/clojure/currying$20hickey|sort:date/clojure/TjvA5AQArUs/9bN78s4w-VkJ

There is no appl function in today's Clojure core. I do not know the history of it, and wasn't aware of it until doing keyword searches through old Google group messages.

That post also speaks to why + can't be curried as well as being variadic:

(+) ;=> 0
(+ n) ;=> n -- does not mean "add n"
(+ 1 2 3 4) ;=> 10
edited by
I see that makes sense! Since variadic and keyword arguments are supported it wouldn't be possible to have auto-currying.

However, you could write a curry function that takes an arity and a function that works that way.  Alternatively, various macros have been proposed as well. Although, introducing that behavior may throw people off. Thanks for the insight!
+1 vote

If you don't mind using an external library, currying is possible in Clojure: