Let’s compare how we print the class-path in Clojure and how we do it on Java.
In Clojure:
(println (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader))))
In Java:
import java.net.URL; import java.net.URLClassLoader; public class PrintClasspath { public static void main(String[] args) { //Get the System Classloader ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader(); //Get the URLs URL[] urls = ((URLClassLoader)sysClassLoader).getURLs(); for(int i=0; i< urls.length; i++) { System.out.println(urls[i].getFile()); } } }
To be fair, the output is not the same, but the effect is.
Related posts:

#1 by Matt on 2010-03-10 - 05:49
Cool one liner. I’m just starting in on Clojure and played around until I could get the Clojure version to print in the same format as your Java version:
(doseq [url (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader)))]
(println (.getFile url)))
Love it!
Matt´s last blog: The super easy way to use Emacs and Slime with Clojure