I have a list with cons-pairs, e.g. '((a . 3) (b . 2)). I want to remove a cons-pair destructive if the first element in the cons-pair matches var. My function cannot remove the cons-pair if there is only one cons-pair in the list or if it is first in the list.
(defun delete-bindings! (var symbol-table)
(cond
((endp symbol-table) '())
((eql var (caar symbol-table))
(delete-bindings! var (cdr symbol-table)))
(t (setf (cdr symbol-table) (delete-bindings! var (cdr symbol-table)))
symbol-table))))
What am I missing?
Thanks!
Your function is always returning
'(), I think (can’t be sure since you didn’t show the whole thing).Perhaps:
Addendum:
You must use the result of this function, not simply depend on its side effects:
Second addendum
If you need a data structure that may be destructively modified with all references to it updated, you’ll need another level of indirection.
E.g.,