The Program is supposed to find each symbol in the List, that comes after a certain symbol. The function gets to parameters passed in. A List which could contain nested-lists and a symbol. The function has to scan thru the list and search for the given symbol and print the symbols that come after the given symbol.
Examples:
(find-all 'a '((b a) ((c a b)))) --> (c b)
(find-all 'a '(b (a a) c)) --> (a c)
(find-all 'a '(b d c e)) --> nil
My Code So Far:
(defun find-all (a list)
(if (consp list)
(if (consp (car list))
(find-all a (car list))
(if (eq a (car list))
(cons (car(cdr list)) (find-all a(cdr list)))
(find-all a(cdr list))))))
This code works except when the symbol its looking for is the last atom in the list. it fails in these test cases:
(find-all 'a '((b a) ((c a b)))) --> (c b)
(find-all 'a '(b (a a) c)) --> (a c)
but works fine in these cases:
(find-all 'a '(b a c a e)) --> (c e)
The issue is probably at my cons statement and i am unable to fix this.