On Fri, Dec 23, 2011 at 3:45 AM, JuanManuel Gimeno Illa <jmgim...@gmail.com>wrote:
> Hi all, > > - first I watched Daniel Spiewak's talk Extreme Cleverness: Functional > Data Structures in > Scala<http://www.infoq.com/presentations/Functional-Data-Structures-in-Scala>, > I got the idea of implementing some of them in Clojure > - then I bought okasaki's book, but all the examples were in ML > - then I watched David Nolen's talk The Mapping > Dilemma<http://www.infoq.com/presentations/The-Mapping-Dilemma>, > and I though clojure.match could be very useful > > and the result (mainly a proof of concept) is: > > - https://github.com/jmgimeno/okasaki-clojure > > that allows the translation of some of the implementations in ML into > Clojure. > > For instance, unbalanced binary trees can be implemented as: > > > (defdatatype > ::UnbalancedBST > Empty ; empty tree > (Node a x b)) ; tree with root x, left subtree a and right subtree b > (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)) > > Enjoy! > > Juan Manuel > > Very, very cool. Is this just sugar for map pattern matching? I'd like to fully support types/records as they provide significant performance benefits. Probably won't happen in the near, near future - unless of course somebody wants to take a stab at it :) David -- 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