Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;L3P9
- ;Write a function that removes all occurrences of an atom from any level of a list.
- ;removeEl(l a)
- ; l - list of elements
- ; a - given atom that will be removed from l
- ;removeEl(l, a)={
- ; nil, if l is null
- ; l, if l == a
- ; nil, if l != a
- ; append of lists returned by the mapcar call of a
- ; lambda(I used a lambda function because removeEl has 2 parameters) function on l, otherwise
- ;}
- (defun removeEl(l a)
- (cond
- ((null l) nil)
- ((and (atom l) (not (equal l a))) (list l))
- ((atom l) nil)
- (T (apply #'append (mapcar (lambda (ll) (removeEl ll a)) l)))
- )
- )
- (write(removeEl (list 1 2 3 (list 4 1 (list 5 1)) 6 1) 1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement