Tuesday, January 24, 2012

Beginning with Clojure

I am, by heart, a linguist, not a computational linguist. I was trained in Edinburgh, which is theoretically heavy, although not in Chomskyan, traditional linguistics. What I learned of Python I essentially taught myself, and there's no limit to my ignorance with traditional programming languages. That doesn't mean I'm not willing to try something new - far from it.

So, here we go. Rather than sit and pretend I haven't been twiddling my thumbs or busy for the past few months, I'm going to come straight out and say that is exactly what has been happening. I like blogging as I go along, though.

Install Clojure from this site. And here is where I ran into my first problem. I downloaded Clojure 1.3.0, unzipped it into my 'code' folder, and then cd'd in there in the Terminal. (I run a Mac.) The site suggests running this:
java -cp clojure.jar clojure.main
Well, that didn't work. (Neither did posting code snippets on Blogger, it seems. update: nevermind.) Instead, I got this:

Exception in thread "main" java.lang.NoClassDefFoundError: clojure/main
Caused by: java.lang.ClassNotFoundException: clojure.main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

This is because there's an issue where it is packaged, and you need to call it by the specific package name. Quick fix, and...:
java -cp clojure-1.3.0.jar clojure.main Clojure 1.3.0
We're properly off!

I've been messing around with clojure on and off for a while now, over here. I highly suggest the tutorial, it is great. (I also highly suggest checking out this post on why Clojure Con was great, but that's not really on topic.

Depending on your development style, you may also want

  • line editing and history at the REPL
  • a syntax-highlighting editor
  • package management
  • automated builds
  • a full IDE
  • a tutorial environment
The site suggests all of those. I'm not so sure. I generally do all of my code with the Terminal and with MacVim. I'll be relying heavily on Vim for Clojure.

That's enough for this post. I'll put more up tomorrow, I hope! I know I'm late, but I view this as a running project and not an end-based one. Again, I'm a linguist, not a coder. So this is a long process.

1 comment:

  1. I recommend skipping the nonsense that is the default REPL in Clojure, the "Getting started" page on the Clojure website is horrible, I encountered the exact same issues to you when I was starting out

    Instead use Leiningen, the de facto Clojure build tool, you can launch a REPL quite easily by simply launching "lein repl"