#! /usr/local/bin/clisp -C (defun deleteall (atm lis) ;; problem 5 solution (cond ( (null lis) '() ) ;; return NIL for a null list ( (eql atm (car lis)) (deleteall atm (cdr lis)) ) (t (cons (car lis) (deleteall atm (cdr lis)) )) ) ) (format t "~%Problem 5:~%") (format t "Delete B from the list (A B C B)?") (print (deleteall 'B '(A B C B) ) ) (format t "~%Can we delete D from the list (A B C)?") ;; use ~% for newline (print (deleteall 'D '(A B C B) ) ) ;; ------------------------------------------------------------------------- (defun deleteall2 (atm lis) ;; problem 7 solution (cond ( (null lis) '() ) ;; return NIL for a null list ( (not (listp (car lis) ) ) (cond ( (eql atm (car lis)) (deleteall2 atm (cdr lis)) ) (t (cons (car lis) (deleteall2 atm (cdr lis)) )) )) (t (cons ( deleteall2 atm (car lis)) (deleteall2 atm (cdr lis)) )) ) ) (format t "~%~%Problem 7:") (format t "~%Delete B from the list (A B C)?") (print (deleteall2 'B '(A B C B) ) ) (format t "~%Can we delete D from the list (A B C)?") ;; use ~% for newline (print (deleteall2 'D '(A B C B) ) ) ;; ------------------------------------------------------------------------- (defun myreverse (lis) ;; problem 9 solution (cond ( (null lis) '() ) ;; return NIL for a null list (t (append (myreverse (cdr lis)) (cons (car lis) () ))) ) ) (format t "~%~%Problem 9:") (format t "~%Reverse the list (A B C B)?") (print (myreverse '(A B C B) ) )