School Commit Init
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
; 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)
|
||||
Reference in New Issue
Block a user