I have several functions I need to write, and the first one is simply to add an atom (integer) to the last element of the list (all integers).
Test 1:
List is (1 2 3 4), and x is 5
Output should be: (1 2 3 9)
Test 2
List is (1 2 3 (4 5) ), and x is 5
Output should be: (1 2 3 (9 10))
so far I can add a specific atom (number) to all elements in a list like this:
Code: Select all
(defun addingIt (L num)
( cond
( (eq L nil) nil )
( (append (list (+ (car L) num) ) (addingIt (cdr L) num ) ) )
)
)
but not to the last element of the list