Wednesday, March 25, 2009

delete-car function

I stumbled on this page and started to solve the problems, Here is solution to the ex4.

Define (delete-car list) to modify and return list with the first element of list deleted.

> (setq l (list 'a 'b 'c))
(A B C)
> (delete-car l)
(B C)
> L
(B C)
Solution:
(defun delete-car (l)
(setf (car l) (cadr l))
(let ((tmp (cddr l)))
(setf (cdr l) tmp))
(if (equal l '(())) nil l))

No comments:

Post a Comment