Sunday, February 21, 2010

Setting up Clojure 1.1.0 on Mac OSX

As part of the Lambda Lounge, established by Alex Miller (Thanks!!), we have started a group to study the SICP. We just started and are going virtual... if you would like to participate, email or tweet me (@kensipe). In the process of studying SICP and LISP, I plan on focusing on Clojure. Clojure was previously on my machine as I was reading Stu's book Programming Clojure, however increased usage would require some maturing of my tools. This led to the discovery of Mark Reid's blog on Setting up Clojure for Mac OS X, however I assume based on updates and changes over the last year, it requires some updates.

Read Mark's blog first... getting clojure, the clojure-contrib and jline. Here are the differences:
  • Create an environment variable CLOJURE_HOME assigned to the directory for clojure
  • Create the /bin directory for the clj script included below
  • Add $CLOJURE_HOME/bin in the $PATH
  • Clojure is distributed with clojure.jar in the CLOJURE_HOME... so I maintain that. It is expected that contrib and jline are in the same directory.
  • Mark's clj script has been updated below... The previous script invokes classes which are depreciated.
Here is the updated script:

#!/bin/bash
# Runs Clojure using the classpath specified in the `.clojure` file of the
# current directory.
#
# Ken Sipe 2010-02-20
# Inspired by Mark Reid
# original: http://github.com/mreid/clojure-framework/blob/e1c80cc650f448713243be8272dba1fa3c1a7cea/clj
#
# This scripts expects $JAVA_HOME and $CLOJURE_HOME to be defined for the system it is running on
# The clojure.jar is standardly in the clojure_home dir (and not in the lib directory), so
# the expectation is that clojure-contrib.jar and the jline.jar are placed in the same dir

CLJ_DIR=$CLOJURE_HOME
CLOJURE=$CLJ_DIR/clojure.jar
CONTRIB=$CLJ_DIR/clojure-contrib.jar
JLINE=$CLJ_DIR/jline-0_9_5.jar
CP=$PWD:$CLOJURE:$JLINE:$CONTRIB

# Add extra jars as specified by `.clojure` file
if [ -f .clojure ]
then
CP=$CP:`cat .clojure`
fi

if [ -z "$1" ]; then
java -server -cp $CP \
jline.ConsoleRunner clojure.lang.Repl
else
java -server -cp $CP clojure.main -i $*
fi
Love the TextMate support and the history support in JLine!

15 comments:

Alex Miller said...

This is roughly how I got started but I've since run into ClojureX which aims to set up a full working Clojure environment including emacs, TextMate, etc. I'm hoping to get some time soon to try it.

And I've heard that on Windows, Clojure Box is the way to go.

Jason Gritman said...

I've used the Clojure Eclipse plugin on Mac OSX for Clojure development. You can run the RPEL in Eclipse and the integrated debugger is really useful.

Purohit D said...

Sun Java is one of the most flexible platform for application development Sun Java development gives the way to develop complex applicaton development.

Purohit D said...

Sun Java is one of the most flexible platform for application development Sun Java development gives the way to develop complex applicaton development.

劉WileyMares said...

how do u do?

esthermelvin said...

Man proposes, God disposes.............................................................

vickiekurt said...

Today is the first day of the rest of your life. ............................................................

RoseH_Huls21365 said...

More haste, less speed...................................................................

張雅筑張雅筑 said...

不論做什麼事,相信自己,別讓別人的一句話,把你擊倒。..................................................

偉倫偉倫 said...

不會從失敗中找尋教訓的人,成功之路是遙遠的。.................................................

恩宛玲如 said...

Quality is better than quantity...................................................................

俊王王王王霖王王 said...

It is never too late to learn.......................................................................

lala said...

Thanks for your post and welcome to check: here
.

Linda said...

Technical thought you have done the good work keep it up

shahzaib khan said...

Forex Market Analysis, Indian Forex Market Updates, Pakistan forex News, New York Stock Updates, World Wide Stock Updates and Much More Forex updates
LatestFxMarket.Com