In Lisp, a list has two parts: the "head" ( car
) and the "tail" ( cdr
). The head is a common element of the list, and the tail is the rest of the list (or nil
, if the list is over). You can create a list implicitly by using:
(a b c d)
Or explicitly, using .
:
(a . (b . (c . (d . nil))))
So, if your AGENDA
list contains nil
, and you want to add an element to it, replace it with a new list, with the new element in the head and the old element in the tail:
(setq AGENDA '(("Isabel" 3233876) . ,AGENDA))
All that remains is to turn it into a function:
(defun incluir (lista elemento) '(,elemento . ,lista))
(setq AGENDA (incluir AGENDA '("Isabel" 3233876)))
Example in ideone . Q. I have little experience with Lisp, there is certainly a simpler way of creating these lists without being backtick / comma, but I do not remember ...