Clojure's a cutting edge lispy language, but has shared a common problem with Java. In the past, it took too long starting up to use Clojure for creation of command line tools. When you type
or any other command, you expect immediate gratification, not ten seconds of painful lag. Clojure's finally on the command line train.
Now, I'm not the first coder to make fast command line apps with Clojure, but I'm still excited to share what I learned. So hold on tight. I'm going to give a very quick overview on how to create extremely fast command line tools with Clojure.
These instructions work with OS X. They should work for any of the varieties of *nix out there. You'll need to modify the instructions to pull off Windows, but it shouldn't be too horrible to get working on Windows. The basic steps are all the same.
The first step to any Clojure installation is lein, more formally known as Leiningen. Leiningen provides commands (with templates) for creation of base Clojure and ClojureScript projects. It has a whole bunch of plugins that it very happily downloads and installs with simple modifications of property files. Even the CounterClockwise Clojure plugin for Eclipse uses Leiningen.
Visit leiningen.org to grab the lein script or lein.bat for your *nix or Windows OS. There are very nice installation instructions on the lein home page.
The mies template actually generates a web page with associated *.js files. All you want is the *.min.js file that it generates when it compiles.
Create a nice ClojureScript project with the following command. (Leiningen handles the mies installation for you.)
lein new mies hello-world
lein is the tool. new tells lein that you want a new project. mies indicates that you want to use the mies template for creating the new project. hello-world is the name of the new project.
Once you cd into your new project, you can track down and modify your *.cljs source file. Notice it is in a *.cljs instead of a *.clj file. Your source file will be at:
To build your project, issue the following command from the project's root directory—the hello-world directory.
lein cljsbuild once
lein cljsbuild auto
While your in the the hello_world.min.js file add the following line to the beginning of the file. It should be on it's own line, not sharing a line with the previous first line of code.
You will need to modify that slightly for Windows, but essentially, you want the node command called at the beginning of your file so the rest of the file is interpreted by Node.js.
Save and exit the file. Rename the *.min.js file to hello or for Windows users, hello.bat. No file extension is needed on *nix. Make the file executable with a command like,
chmod u+x hello
chmod 755 hello
Even though the site claims it's out of date, I like the node installation instructions here. For OS X users, you need to install the Xcode and git apps, and then run git, configure, make and make install the node project.
Once you have Node.js up and running with the node command, you're done. That's all there is to getting everything ready. Now if you put your hello file in the path, you should have a very fast command line responding with Hello World!