Representing A Tree in Clojure

前端 未结 3 538
挽巷
挽巷 2020-12-28 11:43

What would be an idiomatic way to represent a tree in Clojure? E.g.:

     A
    / \\
   B   C
  /\\    \\
 D  E    F

Performance is not imp

3条回答
  •  感情败类
    2020-12-28 12:26

    Trees underly just about everything in Clojure because they lend themselves so nicely to structural sharing in persistent data structure. Maps and Vectors are actually trees with a high branching factor to give them bounded lookup and insert time. So the shortest answer I can give (though it's not really that useful) is that I really recommend Purely functional data structures by Chris Okasaki for a real answer to this question. Also Rich Hickey's video on Clojure data structures on blip.tv

    (set 'A 'B 'C)
    

提交回复
热议问题