title: Common Lisp: Appending a nested plist efficiently
body: <p>I am using a nested plist in order to create a structure of objects (CLOS type), passing on the nested ones to its parts. I want to append the nested plist in an iterative way, but therefore I want to do it efficiently in terms of time and memory.</p>
  
  <p>The below example shows the delta due to one iteration:</p>
  
  <pre><code>'(:airframer "Boeing" :type "777" :wing-plist ((:side :left :winglet? nil)
                                                  (:side :right :winglet? nil)))
  </code></pre>
  
  <p>into</p>
  
  <pre><code>'(:airframer "Boeing" :type "777" :wing-plist ((:type :main-wing :side :left)
                                                  (:type :main-wing :side :right)
                                                  (:type :stabilizer :size :left)))
  </code></pre>
  
  <p>I already read that the use of vectors instead of lists might help, as you access elements without too much penalty: <a href="https://stackoverflow.com/questions/170931/replace-an-item-in-a-list-in-common-lisp">Replace an item in a list in Common Lisp?</a>. However, I would really like to bypass the use of vectors.</p>
  
  <p>Furthermore, I think the use a destructive function would save memory and hopefully calculation time. </p>
  
  <p>This is how I solved it now at the moment, but I have the feeling that it is not elegant and efficient. The function <code>fill</code> is used for destructiveness.</p>
  
  <pre><code>(defun append-nested-plist (plist key sub-plist)
    (let* ((key-pos (position key plist)))
      (fill plist (append (getf plist key) (list sub-plist))
            :start (+ key-pos 1) :end (+ key-pos 2))))
  </code></pre>
  
  <p>I am looking forward to your answers.</p>