I get a '-Program stack overflow' prompt in clisp when I try to execute the following recursive function that, I believe, returns the most common element in a list:
(defun greater-member (lst)
(cond ((null (cdr lst))
(cons (car lst) (count-if #'(lambda (x) (eql x (car lst))) lst)))
((>= (count-if #'(lambda (x) (eql x (car lst))) lst)
(count-if #'(lambda (x) (eql x (car (remove (car lst) lst)))) lst))
(greater-member (remove (car (remove (car lst) lst)) lst)))
(t (greater-member (remove (car lst) lst)))))
e.g greater-number should return as follows:
>(greater-number '(a a a b b b b c))
(b . 4)
May I ask, what is causing the overflow? I've gotten rid of all the little syntax errors by repeatedly executing greater-number in clisp- the function seems to hold logically.