-;;;; utilities
-
-;;; Like ANY and EVERY, except that we handle two-arg uncertain
-;;; predicates. If the result is uncertain, then we return DEFAULT
-;;; from the block PUNT-TYPE-METHOD. If LIST-FIRST is true, then the
-;;; list element is the first arg, otherwise the second.
-;;;
-;;; FIXME: The way that we return from PUNT-TYPE-METHOD rather ruins
-;;; the analogy with SOME and EVERY, and completely surprised me (WHN)
-;;; when I was trying to maintain code which uses these macros. I
-;;; think it would be a good idea to redo these so that they really
-;;; are analogous to EVERY and SOME. And then, while we're at it, we
-;;; could also make them functions (perhaps inline) instead of macros.
-(defmacro any-type-op (op thing list &key (default '(values nil nil))
- list-first)
- (let ((n-this (gensym))
- (n-thing (gensym))
- (n-val (gensym))
- (n-win (gensym))
- (n-uncertain (gensym)))
- `(let ((,n-thing ,thing)
- (,n-uncertain nil))
- (dolist (,n-this ,list
- (if ,n-uncertain
- (return-from punt-type-method ,default)
- nil))
- (multiple-value-bind (,n-val ,n-win)
- ,(if list-first
- `(,op ,n-this ,n-thing)
- `(,op ,n-thing ,n-this))
- (unless ,n-win (setq ,n-uncertain t))
- (when ,n-val (return t)))))))
-(defmacro every-type-op (op thing list &key (default '(values nil nil))
- list-first)
- (let ((n-this (gensym))
- (n-thing (gensym))
- (n-val (gensym))
- (n-win (gensym)))
- `(let ((,n-thing ,thing))
- (dolist (,n-this ,list t)
- (multiple-value-bind (,n-val ,n-win)
- ,(if list-first
- `(,op ,n-this ,n-thing)
- `(,op ,n-thing ,n-this))
- (unless ,n-win (return-from punt-type-method ,default))
- (unless ,n-val (return nil)))))))
-
-;;; Compute the intersection for types that intersect only when one is a
-;;; hierarchical subtype of the other.
-(defun vanilla-intersection (type1 type2)
- (multiple-value-bind (stp1 win1) (csubtypep type1 type2)
- (multiple-value-bind (stp2 win2) (csubtypep type2 type1)
- (cond (stp1 (values type1 t))
- (stp2 (values type2 t))
- ((and win1 win2) (values *empty-type* t))
- (t
- (values type1 nil))))))