Files
School/Anul 2/Semestrul 1/Programare logica si functionala/l3.lisp
T
2024-08-31 12:07:21 +03:00

16 lines
539 B
Common Lisp

; 12. Write a function that substitutes an element through another one at all levels of a given list.
; substitute-element (old new lst):
; new if lst is atom and equal to old
; lst if lst is atom and not equal to old
; (substitute-element old new x) for each x in lst otherwise
(defun substitute-element (old new lst)
(cond ((and (atom lst) (equal lst old)) new)
((atom lst) lst)
(t (mapcar #'(lambda (x) (substitute-element old new x)) lst))))
(print (substitute-element 'a 'z '(a (b a) (c (d a e)))))
(exit)