home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume10 / comobj.lisp / part02 / co-sfun.l < prev    next >
Encoding:
Text File  |  1987-07-30  |  5.5 KB  |  202 lines

  1.  
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ; File:         co-sfun.l
  5. ; RCS:          $Revision: 1.1 $
  6. ; SCCS:         %A% %G% %U%
  7. ; Description:  Override System Functions
  8. ; Author:       James Kempf
  9. ; Created:      March 10, 1987
  10. ; Modified:     March 10, 1987  13:31:39 (Roy D'Souza)
  11. ; Language:     Lisp
  12. ; Package:      COMMON-OBJECTS
  13. ; Status:       Distribution
  14. ;
  15. ; (c) Copyright 1987, HP Labs, all rights reserved.
  16. ;
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18. ;
  19. ; Copyright (c) 1987 Hewlett-Packard Corporation. All rights reserved.
  20. ;
  21. ; Use and copying of this software and preparation of derivative works based
  22. ; upon this software are permitted.  Any distribution of this software or
  23. ; derivative works must comply with all applicable United States export
  24. ; control laws.
  25. ; This software is made available AS IS, and Hewlett-Packard Corporation makes
  26. ; no warranty about the software, its performance or its conformity to any
  27. ; specification.
  28. ;
  29. ; Suggestions, comments and requests for improvement may be mailed to
  30. ; aiws@hplabs.HP.COM
  31.  
  32. ;;;-*-Mode:LISP; Package:(CO (PCL LISP)); Base:10; Syntax: Common-lisp-*-
  33. ;;;
  34. ;;; *************************************************************************
  35. ;;; Copyright (c) 1985 Xerox Corporation.  All rights reserved.
  36. ;;;
  37. ;;; Use and copying of this software and preparation of derivative works
  38. ;;; based upon this software are permitted.  Any distribution of this
  39. ;;; software or derivative works must comply with all applicable United
  40. ;;; States export control laws.
  41. ;;; 
  42. ;;; This software is made available AS IS, and Xerox Corporation makes no
  43. ;;; warranty about the software, its performance or its conformity to any
  44. ;;; specification.
  45. ;;; 
  46. ;;; Any person obtaining a copy of this software is requested to send their
  47. ;;; name and post office or electronic mail address to:
  48. ;;;   CommonLoops Coordinator
  49. ;;;   Xerox Artifical Intelligence Systems
  50. ;;;   2400 Hanover St.
  51. ;;;   Palo Alto, CA 94303
  52. ;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
  53. ;;;
  54. ;;; Suggestions, comments and requests for improvements are also welcome.
  55. ;;; *************************************************************************
  56.  
  57. (in-package 'common-objects :nicknames '(co) :use '(lisp pcl walker))
  58.  
  59. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  60. ;    Overridden System Functions
  61. ;
  62. ;  The semantics of CommonObjects requires that the Lisp functions EQL, EQUAL,
  63. ;  EQUALP, and TYPEP go through the corresponding universial methods rather
  64. ;  than having their default behavior, and that TYPE-OF return the CommonObjects
  65. ;  type. To avoid circularity problems, these functions are defined as
  66. ;  special, non-interned symbols, and are SHADOWING-IMPORTED into the
  67. ;  package by the user if this behavior is desired. Note, however,
  68. ;  that the default Lisp symbols can't be specialized because otherwise
  69. ;  circularity problems in PCL functions like CLASS-OF may occur. An application
  70. ;  wanting to use them must call the function IMPORT-SPECIALIZED-FUNCTIONS
  71. ;  (below) to get access.
  72. ;
  73. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  74.  
  75. (eval-when (load eval)
  76.  
  77.   (progn
  78.  
  79.    ;;For TYPE-OF
  80.  
  81.     (setf 
  82.       (symbol-function 
  83.         (cdr (assoc ':type-of *special-functions-list* :test #'eq))
  84.       )
  85.       (function (lambda (object) (class-name (class-of object))))
  86.  
  87.     ) ;setf
  88.  
  89.    ;;For TYPEP
  90.  
  91.     (setf 
  92.       (symbol-function 
  93.         (cdr (assoc ':typep *special-functions-list* :test #'eq))
  94.       )
  95.       (function
  96.         (lambda (object type) 
  97.           (cond
  98.  
  99.             ;;Object is a CommonObjects instance
  100.  
  101.             ( 
  102.               (instancep object)
  103.           (keyword-standin::typep object type)
  104.             )
  105.  
  106.             ;;Type is a CommonObjects type
  107.  
  108.             (
  109.               (member type (defined-classes))
  110.               NIL
  111.             )
  112.  
  113.             ;;Default
  114.  
  115.             (
  116.               T        
  117.               (lisp::typep object type)
  118.             )
  119.  
  120.           ) ;cond 
  121.         )
  122.       )
  123.     ) ;setf
  124.  
  125.    ;;For EQL
  126.  
  127.     (setf 
  128.       (symbol-function 
  129.         (cdr (assoc ':eql *special-functions-list* :test #'eq))
  130.       )
  131.       (function
  132.         (lambda (object1 object2) 
  133.           (if (instancep object1)
  134.         (keyword-standin::eql object1 object2)
  135.             (lisp::eql object1 object2)
  136.           )
  137.         )
  138.       )
  139.     ) ;setf
  140.  
  141.    ;;For EQUAL
  142.  
  143.     (setf 
  144.       (symbol-function 
  145.         (cdr (assoc ':equal *special-functions-list* :test #'eq))
  146.       )
  147.       (function
  148.         (lambda (object1 object2) 
  149.           (if (instancep object1)
  150.         (keyword-standin::equal object1 object2)
  151.             (lisp::equal object1 object2)
  152.           )
  153.         )
  154.       )
  155.     ) ;setf
  156.  
  157.    ;;For EQUALP
  158.  
  159.     (setf 
  160.       (symbol-function 
  161.         (cdr (assoc ':equalp *special-functions-list* :test #'eq))
  162.       )
  163.       (function
  164.         (lambda (object1 object2) 
  165.           (if (instancep object1)
  166.         (keyword-standin::equalp object1 object2)
  167.             (lisp::equalp object1 object2)
  168.           )
  169.         )
  170.       )
  171.     ) ;setf
  172.  
  173.   ) ;progn
  174.  
  175. ) ;eval-when
  176.  
  177. ;;import-specialized-functions-Import the specialized functions into
  178. ;;  the current package. This will override the Lisp package 
  179. ;;  symbols.
  180.  
  181. (defmacro import-specialized-functions ()
  182.  
  183.   (let
  184.     ( (import-list NIL) )
  185.  
  186.     `(shadowing-import
  187.       ',(dolist (p *special-functions-list* import-list)
  188.          (push (cdr p) import-list)
  189.        )
  190.  
  191.       )
  192.     )
  193.  
  194. ) ;end import-specialized-functions
  195.  
  196. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  197.  
  198.  
  199.  
  200.