Printing the class-path in Clojure

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. How to create a Clojure application
  2. Printing emails in Django
  3. Hacking on the Clojure application

About J. Pablo Fernández

http://pupeno.om
This entry was posted in rant and tagged , , . Bookmark the permalink.

One Response to Printing the class-path in Clojure

  1. Matt says:

    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 =-.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre user="" computer="" escaped="">