I am a lisp novice and I am trying to manipulate lists in lisp. The is from practical tutorial in uni. When i call the function the first element in the list need to be incremented by one and the rest to remain as it was.
Here is an example:
(inc-1st '(1 2 3 4)) => (2 2 3 4)
I tried to solve it but my first number from the list is not printing. Here is my code:
(defun inc-1st (list)
(and (+ 1(car list)) (cdr list)))
and the output is: (2 3 4)
The standard CL macro INCF will do what you want:
(Try
(macroexpand (incf (first list)))to see how it works.)Thus your function would be something like
Note the difference between printing value and returning it: the function above returns
listwhile the REPL prints the return value.