2010-05-15

Few reminders to the very 1st steps to application development in Clojure

Just a few reminders for myself for now...

Get lein.
Get emacs with elpa; use it to get swank-clojure into emacs.

Do lein new project_name
Modify project.clj to use Incanter and Swank, so it should include something like this:

:dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"]
              [org.clojure/clojure-contrib "1.2.0-SNAPSHOT"]
              [incanter "1.2.3-SNAPSHOT"]]
:dev-dependencies [[swank-clojure "1.2.1"]
                   [jline "0.9.94"]]

(edit: turns out incanter will use/import the right clojure libraries for you, but you still should specify which version of clojure and contrib you want to use.  Also note leiningen/lein-swank "1.1.0" is being replaced by swank-clojure)

Do lein deps
Do lein swank
From emacs, do M-x slime-connect

Write your code in files in src/project_name
From the repl in emacs, do (load-file "path/to/code_file.clj") to load the code so you can run it manually to inspect it.  Do (remove-ns 'main-ns-in-code-file) to start over and re-load the file for further inspection (say after you'd done some edits).

(edit: unfortunately, it looks like Java doesn't allow dynamically changing the classpath, so if you write a new file new_file.clj then you'll have to restart the repl or the swank server)

Oh, make sure file names do not include the "-" character even if the namespace you use has a "-" character in it; replace it with a "_" instead in the file name (the namespace can continue to use the "-" though).

You'll need a -main function and an addition to the project.clj file, but that's all I want to note down for now.

(edit: also check out this intro for more readable info from the Incanter web site. My stuff above was more like a brain-dump of mental notes.)

No comments: