So I am learning Lisp at school and one of the programs I have to create is one that duplicates the functionality of remove-if-not by using mapcan. I have created the program and it works correctly but I don't understand the output.
Specifically, if I were to run:
(findall 'numberp '(1 a 3))
The output is: (1 3)
The program is the following:
(defun findAll (fct l)
(cond
((null l) nil)
((mapcan (lambda(x) (if (funcall fct x) (list x) nil )) l))
)
)
My understanding of the solution is the following: "For each of the elements of the list l call the lambda function. If the result of the function fit and the element x returns true, then return the element surrounded by parentheses, otherwise return nil"
What specifically I am not understanding is how a series of consecutive calls to "list(x)" will in the end return a list of atoms such as (1 2).