Define (collect-numbers s-exp) to return a list of all the numbers in the s-expression s-exp. s-exp may be an atom, a list, or a list of s-expressions.
> (collect-numbers 1)Solution:
(1)
> (collect-numbers 'a)
NIL
> (collect-numbers '(1 (b (2 c) ((3)))))
(1 2 3)
(defun collect-numbers (s-exp)
(if (atom s-exp)
(if (numberp s-exp) (list s-exp) nil)
(mapcan #'collect-numbers s-exp)))
No comments:
Post a Comment