;;replace second param with first param (defun replace (new old l) (cond ( (null l) l) ( (eq old (car l)) (cons new( cdr l))) ( t ( (cons (car l) ( replace new old (cdr l))))) ) ) ;;demo replace (replace 3 6 '(6 5 7)) ;(3 5 7) ;;recursion replace all second param with first param (defun replaceall (new old l) (cond ( (null l) l) ( (eq old (car l)) (cons new (replaceall new old (cdr l)))) ( t (cons (car l) (replaceall new old (cdr l)))) ) ) ;;demo replaceall (replaceall 3 6 '(6 5 7 6)) ;(3 5 7 3)