Lisp graph data structures -
i'm reading jorge gajon's trees linked lists in common lisp, includes description of tree done in lisp. author gives basic example:
then gives lisp list representaton:
(1 (2 6 7 8) 3 (4 (9 12)) (5 10 11))
where position implies hierarchy level: 1 first in list, i.e., it's @ top, 2 @ next level, it's top of level, etc. gives caveat:
please note, if need represent trees in production program shouldn’t use lists described here unless have reason. exercise in understanding how cons cells work.
all right, how should 1 represent tree data structure in "production" code? btw, i'd see example of acyclic directed graph, i.e., tree-like has "multiple parent" capabilities. example in diagram above, 8 child of 2, 3. i'm guessing this:
(1 (2 6 7 8) (3 8) (4 (9 12)) (5 10 11))
but seems i've created "shadow" twin of 8 , not relating how 8 child of 3 same 8 has 2 parent. problem gets worse if wanted have 3 12's parent.
(1 (2 6 7 8) (3 8 12) (4 (9 12)) (5 10 11))
the fact 12 in lower hierarchy gets lost in shuffle, speak.
is there , proper treatment (book, etc.) of data structures in lisp/scheme/clojure world? i've found one-off stuff this.
the 'production' code use clos (the common lisp object system) define node
class , operations on graph/tree.
Comments
Post a Comment