clojure tutorial

install openjdk

on linux:

$ sudo aptitude install openjdk-6-jdk

on windows, your need install oracle’s jdk

install lein

on linux or cygwin:

$ export HTTP_CLIENT="wget --no-check-certificate -O"
$ mkdir -p ~/bin
$ wget --no-check-certificate https://raw.github.com /technomancy/leiningen/stable/bin/lein
$ cp lein ~/bin/
$ chmod 755 ~/bin/lein
$ lein version

on windows, download lein.bat, place it to C:

$ wget https://raw.github.com/technomancy/leiningen/stable/bin/lein.bat
$ lein self-install

install node.js

on windows, place node.exe to C:\cygwin\home\zdb\bin

$ wget http://nodejs.org/dist/v0.10.26/node.exe

create a new clojurescript project

$ lein new cljs-helloworld
$ cd cljs-helloworld

edit project.clj:

(defproject cljs-helloworld "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :plugins [[lein-cljsbuild "1.0.1"]]
  :dependencies [[org.clojure/clojurescript "0.0-2138"] [org.clojure/clojure "1.5.1"]]
  :cljsbuild
    {:builds
     [{:source-paths ["src"],
       :compiler
       {:pretty-print true, :target :nodejs, :optimizations :advanced}}]})

this will install lein-cljsbuild, clojurescript:

$ lein deps

rename core.clj:

$ mv src/hello_cljs/core.clj src/hello_cljs/core.cljs
$ vi src/hello_cljs/core.cljs

edit core.cljs:

(ns hello-cljs.core)

(defn -main [& args]
  (println (apply str (map [\space "world" "hello"] [2 0 1]))))

(set! *main-cli-fn* -main)

build:

lein cljsbuild once

run:

node target/cljsbuild-main.js

on windows run repl:

set NODE_PATH=C:\LightTable\plugins\node\node_modules
set path=c:;C:\cygwin\home\zdb\bin;%path%
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_51
set path=%JAVA_HOME%\bin;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib;%path%
set CLASSPATH = ;.%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib

lein repl