문제

I'm using property lists in Common Lisp to represent a binary tree with some additional information. I'd like to be able to dig arbitrarily deep into the tree with a single function, and also modify it accordingly.

In Clojure (which is the other Lisp I use), there exist functions called get-in and assoc-in which can do exactly this, but I haven't found anything similar in Common Lisp. Do they actually exist, or am I going to have to write them?

도움이 되었습니까?

해결책

I have not yet seen the use of nested plists for such a data structure; it may be somewhat unusual. I'd rather expect a structure (defined with defstruct) or class (defined with defclass) representing nodes. An alternative for the case of (not too sparse) binary trees is the implementation as an array, where the root node is at index 0 and each node's children at (2 · i + 1) and (2 · i + 2).

If you insist on using plists, you will have to nest getfs and write a setf expander for nested getfs.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top