Guest User

Untitled

a guest
Sep 17th, 2019
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. ;; [41]> (typep '(1 2 3) '(restricted-list fixnum))
  2. ;; T
  3. ;; [42]> (typep '(1 2 3) '(restricted-list (integer 1 2)))
  4. ;; NIL
  5. ;; [43]> (typep '(1 2 3) '(restricted-list (integer 1 5)))
  6. ;; T
  7.  
  8.  
  9. (defpackage "$$RESTRICTED-LIST-PREDICATES$$" (:USE))
  10.  
  11.  
  12. (defun find-restricted-list-predicate (element-type)
  13. (let* ((name (with-standard-io-syntax (format nil "~S-P" element-type)))
  14. (predicate (FIND-SYMBOL name "$$RESTRICTED-LIST-PREDICATES$$")))
  15. (unless predicate
  16. (setf predicate (intern name "$$RESTRICTED-LIST-PREDICATES$$"))
  17. (eval `(defun ,predicate (list)
  18. (every (lambda (item) (typep item ',element-type)) list))))
  19. predicate))
  20.  
  21.  
  22. (deftype restricted-list (element-type)
  23. `(or null
  24. (and cons
  25. (satisfies ,(find-restricted-list-predicate element-type)))))
Advertisement
Add Comment
Please, Sign In to add comment