Write a LISP function REMOVELAST which removes the last element of a given list. For example: (REMOVELAST ‘(A (A B) C)) Returns the list (A (A B)) and (REMOVELAST ‘(A B (C D))) Returns the list (A B)
(defun REMOVELAST(list)
(reverse (cdr (reverse list)))
)
first the inner reverse will be executed and it will reverse the
list.
Now the last element is the first element.
now we use cdr which will return the list without the first
element.
So the last item of the origiinal list has been removed.
Now we reverse it again, so now we have the origiinal list without the last element
Get Answers For Free
Most questions answered within 1 hours.