Starting up Clojure simple tips

Here’s a couple of things that i use, when learning about Clojure.Im on Mac and using Textmate.

Screencasts & Tutorial

Here are a series of 10 screencasts that i found to be quite useful Intro to Clojure (youtube playlist)

And there’s also Rich Hickey screencasts http://clojure.blip.tv/, but they are longer, so start the with ones above.

For reading material take a look at Mark Volkmann Clojure very complete notes here. And his clojure references here.

Folder Structure for code


bin/
repl.sh
run.sh
lib/
clojure-contrib.jar
clojure.jar
jline-0.9.94.jar
*.jar
README
src/
*.clj
test/
*.clj

Assuming a structure, is possible to do some automation, see next.

Textmate Builds run.sh and repl.sh

To address the issues of including jar’s you want to use in the Classpath here’s a little ruby script that I trigger from Textmate. It looks into the lib/ dir and creates the repl.sh and run.sh scripts:


#!/usr/bin/env ruby -wKU

project_dir=ENV['TM_FILEPATH'].split("/")[0...-1].join("/")

libs_path = Dir[project_dir + "/../lib/*.jar"].collect

File.open(project_dir+"/../bin/run.sh", "w+") do |fil|
fil.puts "java -cp .:#{libs_path.join(':')} clojure.lang.Script #{ENV['TM_FILEPATH']}"
end

File.open(project_dir+"/../bin/repl.sh", "w+") do |fil|
fil.puts "java -cp .:#{libs_path.join(':')} jline.ConsoleRunner clojure.lang.Repl #{ENV['TM_FILEPATH']}"
end

So if you want to use some new jar’s just place them inside the lib/ and trigger this ruby code that will re-generate the the run.sh and repl.sh scripts.

Existing code

Other thing that i keep close by is existing Clojure code examples, i also use Textmate so that they are just a keyboard shortcut away(they are 3 different commands):

 git fetch
mate '/somewhere-in-your-disk/programming-clojure/'

svn up
mate '/somewhere-in-your-disk/clojure-contrib/'

svn up
mate '/somewhere-in-your-disk/svn_clojure/trunk'

you can get this code onto your machine from:

 Clojure core
http://code.google.com/p/clojure/
svn checkout http://clojure.googlecode.com/svn/trunk/ clojure-read-only

Clojure contrib
http://code.google.com/p/clojure-contrib/
svn checkout http://clojure-contrib.googlecode.com/svn/trunk/ clojure-contrib-read-only

Programming Clojure book:
http://github.com/stuarthalloway/programming-clojure/tree/master

API

Another handy keyboard shortcut is to get the clojure api web page, also directly from Textmate, setup a new command with the code:

open http://clojure.org/api

Google it

A lot of people are starting to explore Clojure, so google it and you’ll find a lot of posts and tips on clojure already out there.

1 comment:

fogus said...

I follow a similar code directory scheme, except that I also include a basic ant build script providing build/jar tasks.
-m