Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;L3P9
  2. ;Write a function that removes all occurrences of an atom from any level of a list.
  3. ;removeEl(l a)
  4. ;   l - list of elements
  5. ;   a - given atom that will be removed from l
  6. ;removeEl(l, a)={
  7. ;   nil, if l is null
  8. ;   l, if l == a
  9. ;   nil, if l != a
  10. ;   append of lists returned by the mapcar call of a
  11. ;       lambda(I used a lambda function because removeEl has 2 parameters) function on l, otherwise
  12. ;}
  13. (defun removeEl(l a)
  14.   (cond
  15.     ((null l) nil)
  16.     ((and (atom l) (not (equal l a))) (list l))
  17.     ((atom l) nil)
  18.     (T (apply #'append (mapcar (lambda (ll) (removeEl ll a)) l)))
  19.     )
  20.   )
  21. (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