Prior to discovering Clojure back in 2007, I was a full-time Java programmer. This was long before method handles, method references, lambda expressions, and invokedynamic, so viewing Java through a functional programming lens was not second-nature to me. Regardless, during my early Clojure explorations I fully expected code like the following to "just work":
(defn up-all [strings]
(map .toUpperCase strings))
;; Unable to resolve symbol: .toUpperCase
That is, I[^cdevs] fully expected Clojure to recognize that .toUpperCase
referred to the instance method String.toUpperCase
as a value, and infer how to "do the right thing" with it for each element in the strings
collection handled by map
even though Clojure could never know what it might hold.
Of course, it eventually occurred to me that the actual way to do what I wanted was to wrap the method call in a function instead: