I am posting my latest source code in both Clojure and PLT Scheme:
http://groups.google.com/group/ai-renaissance/files
Both implementations are purely functional. They turned out to be pretty short overall. There are a few interesting Clojure idioms:
PLT Scheme:
(remove ‘b ‘(a b c d))
Clojure:
(remove #{’b} ‘(a b c d))
The notation #{’b} is a set literal with a single symbol ‘b as its element. It turns out that in Clojure, arrays, structures, and sets all act as functions on keys:
user=> (['a 'b 'c] 1) ; array of three elements applied to an index
b
user=> ({:a 1 :b 2 :c 3} :b) ; a map applied to key :b
2
user=> (#{'a 'b 'c} 'a) ; A set applied to an element
a
user=> (#{'a 'b 'c} 'x) ; the same set applied to a non-element
nil
A more accurate translation into scheme would be:
(filter (lambda (item) (not (equal? item 'b))) '(a b c d))
In Clojure the set can be used as a function to identify its members. The remove function uses a predicate function to filter the elements.
One Comment
The idiom becomes more fun when you have multiple items in the set:
(remove ‘#{b d} ‘(a b c d))
-> (a c)