So I'm trying to recursively find palindromes, I've generated a huge nested list that looks like so '((n n n)(n n n)(n n n)) Where n is numbers ofc using the function:
(defun double-lst (lst1 lst2)
(mapcar #'(lambda (n)
(multiply-lst n lst2))
lst1))
the list is absolutely huge. I'm trying to write a recursive function that searches the car and cdr of my list using the template:
(DEFUN func (X)
(COND (end-test-1 end-value-1)
(end-test-2 end-value-2)
(T (combiner (func (CAR X))
(func (CDR X))))))
But I can't seem to get my version or anything I've tried to work. I've tried stuff along the lines of this:
(defun find-palindrome (lst)
(cond ((equal lst (reverse lst)) lst)
(t (or (find-palindrome (car lst))
(find-palindrome (cdr lst))))))
The function find-palindrome is passed (reverse lst) so that it works from the highest values first returning the first palindrome, but I don't know how to get the recursive function to do its stuff. I'd really appreciate an in depth explanation on how to write car/cdr recursion. Thanks :) EDIT: my crappy find-palindrome returns this:
CL-USER> (find-palindrome '((1 2 3 4)(13 4 51 3) (1 2 4 9009)))
; Evaluation aborted on #<TYPE-ERROR expected-type: SEQUENCE datum: 1>.
I'd expect it to return (9009).
find-palindromeand what you would expect it to return? - Scott Hunter