Advertisement
Guest User

Untitled

a guest
Jun 12th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. (defun count-anywhere (search-expr whole-expr)
  2. (let ((result 0)
  3. (count-adder #'(lambda (search-expr whole-expr)
  4. (+ (count-anywhere search-expr (first whole-expr))
  5. (if (rest whole-expr)
  6. (count-anywhere search-expr (rest whole-expr))
  7. 0))))
  8. (found-expr (equal search-expr whole-expr)))
  9. (if (atom whole-expr)
  10. (if found-expr
  11. 1
  12. 0)
  13. (cond
  14. (found-expr 1)
  15. ((> (setf result (funcall count-adder search-expr whole-expr) ) 0) result)
  16. (t 0)))))
  17.  
  18. CL-USER> (count-anywhere '(a) '(a ((a) b) a))
  19.  
  20. 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement