Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun type= (type1 type2)
- "Returns a primary value of T if TYPE1 and TYPE2 are the same type,
- and a secondary value that is true is the type equality could be reliably
- determined: primary value of NIL and secondary value of T indicates that the
- types are not equivalent."
- (multiple-value-bind (sub ok) (subtypep type1 type2)
- (cond ((and ok sub) ; type1 is known to be a subtype of type 2
- ; so type= return values come from the second invocation of subtypep
- (subtypep type2 type1))
- ;; type1 is assuredly NOT a subtype of type2,
- ;; so assuredly type1 and type2 cannot be type=
- (ok
- (values nil t))
- ;; our first result is uncertain ( ok == nil ) and it follows
- ;; from the specified behavior of SUBTYPEP that sub must be NIL
- (t
- (assert (not sub)) ; is the implementation correct?
- (multiple-value-bind (sub2 ok2)
- (subtypep type2 type1)
- (if (and (not sub2) ok2) ; we KNOW type2 is not a subtype of type1
- ;; so our results are certain...
- (values nil t)
- ;; otherwise, either type2 is surely a subtype of type1
- ;; or type2 is not a subtype of type1, but we don't
- ;; know that for sure, in either case our result is negative
- ;; but unsure
- (values nil nil)))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement