Correct usages of Character/isWhitespace include:
(Character/isWhitespace \a) => false
(Character/isWhitespace \ ) => true
However, my first attempt was this, and I find the error confusing.
(Character/isWhitespace "")
=> IllegalArgumentException No matching method found: isWhitespace
=> clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)
The IllegalArgument
part makes sense, but why does it say "no matching method found"? Clearly the function does exist.
Clarification
The reason I'm asking this question is that I'm new to Clojure, and think I'm fundamentally misunderstanding something.
When I type (Character/isWhitespace \a)
, what I think I'm saying is: "I know that there's a Character
namespace, and within that there's a function called isWhitespace
, and I want to call that function and pass in \a
".
On this mental model, my results above are confusing because it seems like Clojure is saying, "whenever you give me an argument type that this function doesn't accept, I'm going to pretend the function doesn't exist." Eg, "you're not allowed to blend bricks, so if you try, I'm going to give you a BlenderDoesntExist error." Which is weird.
Some answers seem to imply that
- The name
Character/isWhitespace
is only part of what Clojure uses to look up the function, and the other part is the type of the argument. (I've done some more searching: is this maybe a multimethod?) - The method is being looked up on a Java class?
A great answer would clarify this process for me.