Advertisement
IRCrpg

Second draft

May 4th, 2023
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. (defun type= (type1 type2)
  2. "Returns a primary value of T if TYPE1 and TYPE2 are the same type,
  3. and a secondary value that is true is the type equality could be reliably
  4. determined: primary value of NIL and secondary value of T indicates that the
  5. types are not equivalent."
  6. (multiple-value-bind (sub ok) (subtypep type1 type2)
  7. (cond ((and ok sub) ; type1 is known to be a subtype of type 2
  8. ; so type= return values come from the second invocation of subtypep
  9. (subtypep type2 type1))
  10. ;; type1 is assuredly NOT a subtype of type2,
  11. ;; so assuredly type1 and type2 cannot be type=
  12. (ok
  13. (values nil t))
  14. ;; our first result is uncertain ( ok == nil ) and it follows
  15. ;; from the specified behavior of SUBTYPEP that sub must be NIL
  16. (t
  17. (assert (not sub)) ; is the implementation correct?
  18. (multiple-value-bind (sub2 ok2)
  19. (subtypep type2 type1)
  20. (if (and (not sub2) ok2) ; we KNOW type2 is not a subtype of type1
  21. ;; so our results are certain...
  22. (values nil t)
  23. ;; otherwise, either type2 is surely a subtype of type1
  24. ;; or type2 is not a subtype of type1, but we don't
  25. ;; know that for sure, in either case our result is negative
  26. ;; but unsure
  27. (values nil nil)))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement