I'm trying to increment elements in a list
by creating a new list
to which I would append
incremented elements of an old list
in dolist
loop.
First I tried this and it didn't work:
(defun increment-list(old-list)
(setq new-list (list))
(when (listp old-list)
(dolist (x old-list) (append new-list (+ x 1)))
(print new-list)
)
)
Then I thought that maybe list
can only be appended with another list
, so I changed dolist
to look like this:
(dolist (x old-list) (append new-list (list (+ x 1))))
Both solutions left gave the same result - new-list
was NIL
.
Currently, I'm using push
, but it makes a reversed list
. I could reverse it again, but it seems to be an unnecessary complication.
I have also found other solutions which I could use. However, I'm eager to find out why append
doesn't work here because according to this answer it should.