Add a method to get to the root of a node tree

This commit is contained in:
Renaud Casenave-Péré 2016-04-09 13:03:18 +02:00
parent 8838362c26
commit dfe1b3940c

View file

@ -10,7 +10,7 @@
#:progress-step
#:loop-with-progress
#:add-hook #:remove-hook #:run-hook
#:node #:parent #:children #:attach-node #:detach-node
#:node #:parent #:children #:attach-node #:detach-node #:root
#:shared-object #:refcount #:inc-ref #:dec-ref
#:extend-array #:shrink-array
#:error-implementation-unsupported
@ -106,6 +106,12 @@
(setf children (delete node children)))))
node)
(defgeneric root (node))
(defmethod root ((node node))
(if (parent node)
(root (parent node))
node))
(defmethod initialize-instance :after ((node node) &key parent)
(attach-node node parent))