I am trying to write a function that returns a list of atoms in a list,lets say i have a list which has both atoms and a list in it and when I run the function it should return a list of atoms inside..
For example:
(func '(2 34 5 (12) 7 (A B C) +))
-> (2 34 7 +)
And I want to try if the arguments inside the result are true such that when I run:
(ATOM ( (func '(2 34 5 (12) 7 (A B C) +)) )
->T
Any ideas on how I can go about it? Books or references?
Using standard CL functions,
If you want to write them yourself, you can fuse the
#'atomin and make two specialized functions, sayremove-atomsandevery-is-atom. But “atom” is a name of a built-in functionatom.One way to write the first is
This builds the result list in a top-down manner using destructive update, which doesn’t violate the spirit of functional programming here because it is used locally, as an implementation technique. This can be seen as a Common-LISP–specific translation of the general functional tail-recursive-modulo-cons code from the other answer.
And the second function: