Sep122009

Breve-alike in Clojure

Filed under: clojure cascade breve 

Lisp has long tended to use DSLs for HTML generation, and Clojure is no different in this regard. In fact, Breve was inspired by Stan which in turn was inspired by these Lisp DSLs.

However, I've tended to like the Breve syntax just a little better than the true s-expression DSLs:

# breve example
html [
    head [
        title [ 'hello, world' ]
    ],
    body [
        div ( id='main' ) [
            'hello, world'
        ]
    ]
]

Clojure provides it's own approach (and Compojure provides a very similar DSL):

;; clojure prxml example
(prxml
   [:html
     [:head
       [:title "hello, world"]
     ]
     [:body
       [:div {:id "main"}
         "hello, world"
       ]
     ]
   ]
 )

Overall, they are quite similar in approach, but the Lisp-like bracket placement continues to disturb me slightly, and I suspect it will disturb my designer (whom I got to eventually love Breve) even more.

Today I was researching Clojure stuff built around Ring and came across Cascade. Cascade includes its own variant of this type of DSL and it's a nice cross between the traditional Lispy s-expression approach and that used by Breve:

(defview index
  [env]
  :html [
    :head [
      :title [ "hello, world" ]
    ]
    :body [
      :div { :id "main" } [
        "hello, world"
      ]
    ]
  ]
)

This is pretty subjective, but I find the bracket placement a bit easier on the eyes and brain.



1 comments Leave a comment


Sep22009

Getting started with Clojure on Ubuntu

Filed under: clojure 

Clojure is a dialect of Lisp, and shares with Lisp the code-as-data philosophy and a powerful macro system. Clojure is predominantly a functional programming language, and features a rich set of immutable, persistent data structures. Clojure runs on the JVM.

To get satisfactory results on Ubuntu, I suggest the following setup:

  1. Remove all the java-gcj stuff that Ubuntu probably has installed:
$ sudo aptitude remove java-gcj*
  1. Install the Sun Java binaries:
$ sudo aptitude install libjline-java sun-java6-jdk sun-java6-jre ant
  1. Download and install git head of Clojure:
$ git clone git://github.com/richhickey/clojure.git
$ cd clojure
$ ant
$ java -cp clojure.jar clojure.main

If the last line presents you with the Clojure REPL (Read-Evaluate-Print-Loop) prompt ("user=>"), then you are have Clojure successfully running.

Next, we want to move Clojure to a more sane place (I chose /usr/local/lib/clojure):

$ cd ..
$ sudo mv clojure /usr/local/lib

Next, we want Jeffrey Chu's Clojure Extras:

$ wget http://github.com/jochu/clojure-extra/zipball/master -O clojure-extra.zip
$ unzip -p clojure-extra.zip "*clojure.conf.sample" > .clojure.conf
$ sudo unzip -p clojure-extra.zip "*clojure" > /usr/local/bin/clojure
$ sudo chmod 755 /usr/local/bin/clojure

Next, edit ~/.clojure.conf and change/uncomment the following lines:

clj=/usr/local/lib/clojure/clojure.jar
clj_ext=~/.clojure
clj_wrapper=jline.ConsoleRunner

Although I don't understand why you should need to, I had to link the jline jar file into ~/.clojure, otherwise java couldn't find it:

$ ln -s /usr/share/java/jline.jar ~/.clojure

Next, install clojure-contrib:

$ git clone git://github.com/richhickey/clojure-contrib.git
$ cd clojure-contrib
$ ant
$ cp clojure-contrib.jar ~/.clojure

At this point you should have a fully functional Clojure install. Just type "clojure" at the command prompt.



0 comments Leave a comment


Sep52009

Clojure Links

Filed under: clojure 

Various links to interesting Clojure stuff.

More will be added as I discover them.

  1. Compojure: Web framework similar to web.py or Sinatra.
  2. Webjure: Web programming.
  3. ClojureSQL: SQL abstraction layer.
  4. Ring: Web framework similar to WSGI or Rack.
  5. JDBC examples: reference for using JDBC with Clojure.
  6. cljrecord: similar to ActiveRecord
  7. Using PostgreSQL with Compojure


0 comments Leave a comment


Sep52009

Clojure mode in Emacs

Filed under: clojure emacs 

You learn something new every day, and today was no different for me.

First off, it turns out Emacs has a package management system (at least since 22). It's called ELPA and it makes it much easier to install Emacs extensions. This is the feature we'll use to install clojure-mode.

First, get ELPA installed: copy and paste the following elisp code from the ELPA site into your *scratch* buffer:

(let ((buffer (url-retrieve-synchronously
              "http://tromey.com/elpa/package-install.el")))
 (save-excursion
   (set-buffer buffer)
   (goto-char (point-min))
   (re-search-forward "^$" nil 'move)
   (eval-region (point) (point-max))
   (kill-buffer (current-buffer))))

Next, eval this code by putting your cursor after the last parentheses and pressing Control+j (C-j). This will install ELPA and create a default ~/.emacs file for you.

Next, we tell the ELPA package to download and install clojure-mode. In emacs, press M-x package-install (Alt+x package-install) and enter clojure-mode when prompted. This will download the package and install it for you so that it's automatically loaded when emacs starts.

That's it! Now whenever you load a .clj file, emacs will switch to clojure-mode.



0 comments Leave a comment


Oct72009

Scriptjure

Filed under: scriptjure clojure 

Scriptjure is a Clojure library for generating Javascript.



0 comments Leave a comment


Dec292009

Another Clojure implementation

Filed under: clojure xronos 

Xronos is a DLR-based Lisp variant. It is a Clojure-like language for .NET. Xronos shares the same syntax and base library as Clojure (but not any source code).



0 comments Leave a comment




Copyright © 2007, Cliff Wells