Tuesday, 22 December 2009

Programming Clojure: Compiling to Disk

I thought I would make a note of this just in case anyone else is as bone-headed as me. In section 3.3 of Programming Clojure (Creating and Compiling Java Classes in Clojure) I couldn't work out how to compile the reader.tasklist library:
(compile 'reader.tasklist)
What I didn't realize, and what I don't think the book makes particularly clear, is that you can't enter the code into the REPL and then compile it. Instead you need to start with the file reader/tasklist.clj and then add the various functions into that file. The compile function compiles the .clj file into Java .class files just as javac compiles .java files in to .class files.

I can't believe it took me so long to work this out. Fortunately I didn't tear out all my hair. I still have a few tufts left.

No comments:

Post a Comment