Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun count-anywhere (search-expr whole-expr)
- (let ((result 0)
- (count-adder #'(lambda (search-expr whole-expr)
- (+ (count-anywhere search-expr (first whole-expr))
- (if (rest whole-expr)
- (count-anywhere search-expr (rest whole-expr))
- 0))))
- (found-expr (equal search-expr whole-expr)))
- (if (atom whole-expr)
- (if found-expr
- 1
- 0)
- (cond
- (found-expr 1)
- ((> (setf result (funcall count-adder search-expr whole-expr) ) 0) result)
- (t 0)))))
- CL-USER> (count-anywhere '(a) '(a ((a) b) a))
- 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement