This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

a very simple function

4 posts · 1134 views

Hi,
I'm really new at the lisp and I need your help.
I have got a list
(setq S '(5 6 4 2))
When I call some function which looks like
(defun add (S N)  (...) )
where S is the list and the N is a number.
This number(N) I want to add at the end of the list. The result should be
(5 6 4 2 N).
For example N=7 then the list is (5 6 4 2 7).
How can I do it ? Please help me.

Thanks in advance. Mike

Re: a very simple function

Another way is to use rplacd [ or (setf (cdr ...) ...)] on the last element of the list to destructively set it to (list N).
Need an online wiki database? My Lisp startup http://www.formlis.com combines a wiki with forms and reports.