Lisp

Last modified Feb. 26, 2009 | Revision 30

Lisp Cycles

Three interesting new Lisp dialects have sprung up in the last couple of years, Nu, Paul Graham’s Arc, and most recently Clojure.

brehaut first got interested in Lisps at university, but the fascination died largely because of the hugely splintered community, and the millions of dialects either sprawlingly complex or starved for support. Nu rekindled my interest but the Ruby with parens design choices coupled with a meager standard library (Cocoa) let it die.

Then came Arc; Much hyped and ultimately a disappointment (‘years of work for a layer ontop of a scheme and no real libraries? No thanks’ is the general sentiment).

Mostly recently Clojure has come onto the scene. At this point its about a year old. It is designed as pragmatic, purely functional lisp with strong support for concurrent programming running on the JVM. Clojure has had the success previous ‘new’ lisps wish they could have achieved.

Brehaut Is currently working on a mail client using clojure and has found it very enjoyable to work with.

Here are a couple of useful functions I have built that may be generally useful.

add-contribs — This function is used to load a set of local jar files to the classpath; i call this from my bootstrapping script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
(import '(java.io File FilenameFilter))
       
(defn add-contribs 
    "Bootstrap the classpath to contain libs in contrib. 
    Given no arguments it will default to the contrib directory in the current working directory."
    ([] (add-contribs (System/getProperty  "user.dir")))
    ([base] (let [cwd (new File base "contrib")
                  file-filter (proxy [FilenameFilter] []
                                (accept [dir name]
                                (not (nil? (re-matches #".*\.jar$" name)))))
                  files (seq (.listFiles cwd file-filter))]
        (dorun (map #(add-classpath (str "file://" (.getAbsolutePath %))) files))))) 

ui-invoke and ui-bind — a wrapper around the swing event queue; used by ui-bind that follows. ui-bind takes a function and decorates it; The decorating function is called in whatever thread wants with the arguments for the original function. That function is invoked on the ui event thread.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
(ns net.brehaut.util
    (:import javax.swing.SwingUtilities))

(defn ui-invoke
    "invokes is argument the event queue (with no arguments)"
    [fun]
    (SwingUtilities/invokeLater fun))

(defn ui-bind
    "Binds a function to run on the Swing Event Queue thread"
    [fun]
    (fn [ & args ] (ui-invoke (fn [] (apply fun args)))))

See Also:

Nu

{ note; this is older content pushed down; my views have since changed — brehaut }

{see also Structure and Interpretation of Computer Programs} and in particular the new Mac OS X language Nu.

My interest in Nu flows from my interest in F-Script as an language for scripting Objective-C / Mac OS X apps. Both Smalltalk and Lisp interest me. Nu however has a few small advantages over F-Script:

  • Supports class creation and extension out of the gate. There are a number of third party F-Script ones, but they arent as nice as Nu.
  • Nu has a broader range of supporting tools. Most importantly, it has ‘nush’ the Nu Shell as standard. Basicly, it has a richer ecosystem as part of its toolset, and the developer seems to have put a lot of effort into making it useful.
  • Macros. I’m embeding Nu into an app that needs to load complex rule descriptions, i was previously using XML but it was lumpy and not really very suited to it. Now im using Nu and some macros to implement it directly and allow flexible and comprehensive scripting. Much nicer. hacked out some Nu stuff
Last modified Feb. 26, 2009 | Revision 30