SHARE
TWEET

Untitled

a guest Sep 17th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top