Wednesday, March 25, 2009

has-number-p

I stumbled on this page and started to solve the problems, Here is solution to the ex1 .
Define (has-number-p s-exp) to return true if the s-expression is or contains a number.
> (has-number-p 1)
T
> (has-number-p 'a)
NIL
> (has-number-p '(a (b (c d) ((3)))))
T

Solution:
(defun has-number-p (s-exp)
(if (atom s-exp)
(if (numberp s-exp) t nil)
(some #'has-number-p s-exp)))

No comments:

Post a Comment