I know this is a newbie question I apologize in advance. I'm writing a recursive function which returns the number of 'o in a given list
(defun garde-o (liste)
(cond
((not liste) 0)
((equal (car liste) 'o) (+ 1 (garde-o(cdr liste))) )
((garde-o(cdr liste)) )
)
)
Instead of returning the number of occurence I would like to return the given list with only the 'o.
Like that:
(garde-o '(a o x & w o o))
should return => (o o o)
I don't want to use pop
,push
,set
... just I can't find of to return this.
Notice that given the number of occurrences, for example 10, you can simply do
or equivalently
To count the 'o in your list, you can do
Thus, a simple solution for your function would be
However, you can do this recursively too
and non-recursively