1

are there any documentation on clojure built-in java method? for example, .toUpperCase from java.lang.String and .indexOf from clojure.lang.PersistantVector.

Is there anyway I can find useful java method without looking at the source code?

LoveProgramming
  • 2,121
  • 3
  • 18
  • 25

3 Answers3

4

As others have pointed out, you can get the java.* and javax.* documentation online pretty easily as it is part of core Java.

For the clojure.*, your best reference is the source. Even so, I'd recommend not relying on it since this code should really be considered an implementation detail of Clojure. You have no guarantee that the functionality won't change in future versions of Clojure and break any code that depends on it.

mikera
  • 105,238
  • 25
  • 256
  • 415
  • in this question [link] (http://stackoverflow.com/questions/4830900/how-do-i-find-the-index-of-an-item-in-a-vector), it seems that using .indexOf is the most simple way to accomplish the job. Should one write his own version in clojure or just use the code in JAVA in such situation? – LoveProgramming Mar 29 '13 at 03:16
  • You should use Java interop for sure when it provides functionality you need (especially for `java.*` classes which are guaranteed to be available and likely to be backward compatible forever). But I suggest wrapping any interop inside a small utility function so that your main code base is Java-interop free. – mikera Mar 29 '13 at 03:24
2

How about the Java API? All of Java's classes and methods are listed there. That covers all of the "clojure built-in java methods".

On the other hand, Clojure's classes are documented in here, Clojure's API. You have to learn to distinguish between Clojure's classes and Java's classes. All packages starting with java.* or javax.* belong to Java and are documented in the first link. The packages starting with clojure.* are from Clojure, you'll find their documentation in the second link.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • apparently I can not find any documentation about clojure.lang.APersistentVector.indexOf(java.lang.Object) in the website you provided – LoveProgramming Mar 28 '13 at 20:54
  • You have to learn to distinguish between Clojure's classes and Java's classes. All packages starting with java.* belong to Java and are documented in the link I provided. The packages starting with clojure.* are from Clojure, you'll find their documentation in Clojure's web page – Óscar López Mar 28 '13 at 21:18
  • In particular, the documentation for the class `clojure.lang.APersistentVector` can be found in [here](http://www.jarvana.com/jarvana/view/org/clojure/clojure/1.3.0/clojure-1.3.0-javadoc.jar!/index.html?clojure/lang/APersistentVector.html) – Óscar López Mar 28 '13 at 21:28
  • That answers my question, thanks a lot. Though I'm still curious why they don't document these methods in clojure's classes as they did for clojure core API, or just wrap them in clojure. I have to trace all the way to java.util.List to find out what indexOf does. – LoveProgramming Mar 28 '13 at 22:56
2

If the package for the class starts with java or javax then you can look it up in the Java documentation on Oracle's website.

For Clojure implementation classes (where the package name starts with clojure) you are probably stuck with looking at the source code. There is documentation for the intended API (the Clojure language) but not for the Java classes implementing it. You may be able to find some articles (like this one) depending on if what you're looking for is something a blogger has taken an interest in.

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276