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, using:
(a b c d)
Or explicitly, using .
:
(a . (b . (c . (d . nil))))
So if your list AGENDA
contains nil
, and you want to add an element in 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’s left then is to turn it into a function:
(defun incluir (lista elemento) `(,elemento . ,lista))
(setq AGENDA (incluir AGENDA '("Isabel" 3233876)))
Example in the ideone. P.S. I have little experience with Lisp, surely there is a simpler way to create these lists than with backtick/comma, but I don’t remember...
I don’t understand your doubt, what this function would do, is there an example? Post also the code you already made, so you can get a better idea of the problem (suggest [Edit] the question with the code).
– mgibsonbr
So what is this list, how is it represented, where is it stored? And these "additional information" are what, is a fixed set of properties, are arbitrary properties? That’s why it helps if you post your current code and an example of what you want.
– mgibsonbr
the function will include additional information of a person in a list. Follow the code: (setq AGENDA 'nil) (setq AGENDA ( include AGENDA '(Isabel 3233876))) this include am not able to do.
– vitor