Hi all, I've been working a "proof of concept" implementation of some data structures from Okasaki's book "Purely functional data structures". The implementations tries to follow the ML implementation describes in the book so I have defined some macros than use clojure.match to allow patter matching and datatypes.
For instance, an unbalances binary search tree can be defined as: (defdatatype ::UnbalancedBST Empty ; empty tree (Node a x b)) ; tree with root x, left subtree a and right subtree b And the insert and member functions as: (defun insert [x t] [x Empty] (Node Empty x Empty) [x ([Node a y b] :as s)] (cond (< x y) (Node (insert x a) y b) (< y x) (Node a y (insert x b)) :else s)) (defun member [x t] [_ Empty] false [x [Node a y b]] (cond (< x y) (recur x a) (< y x) (recur x b) :else true)) If you want to play with it is in https://github.com/jmgimeno/okasaki-clojure Juan Manuel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en