not including theories

Gertjan van Heijst <gertjan@swi.psy.uva.nl>
X-Organisation: Social Science Informatics, University of Amsterdam
X-Address:      Roetersstraat 15, 1018 WB  Amsterdam, The Netherlands.
X-Phone:        +31 20 5256789
X-Fax:          +31 20 5256896
Date: Wed, 24 Mar 1993 17:20:23 +0100
From: Gertjan van Heijst <gertjan@swi.psy.uva.nl>
Message-id: <199303241620.AA08203@swisun31.swi.psy.uva.nl>
To: ontolingua@SUMEX-AIM.Stanford.EDU
Subject: not including theories

Hi,

About two weeks ago I sent a mail to this list about an autoloading
facility for included theories. The problem that I had was that ontolingua
decided to ignore not existing included theories for a particular
implementation BEFORE the implementation specific method
IMPLEMENT-DEFINE-THEORY was called. Because of this there is no way to
build an autoloading facility without actually modifying code in the
ontolingua kernel, However, I consider it an extremely bad idea to make
local changes to the ontolingua kernel because I want to be able to include
new releases of ontolingua without adapting these to my personal needs and
secondly, I want others to be able to use my code once it is finished.

As an experiment I wrote a patch for the ontolingua function
DEFINE-THEORY-INTERNAL that calls the generic function
IMPLEMENT-NOT-INCLUDE-THEORY. The default method for this function does
exactly what ontolingua does: it informs the user and then removes the
theory from the list of included theories. However, for my own
implementation with the name :workbench I've written a method that calls an
autoload function.

This patch should be considered as a PROPOSAL for modifying the public
version of ontolingua. It is probably not the best solution to the problem
that I faced, but I think that something like this is a useful extension to
ontolingua.

Gertjan


--------------------------------------------------------------
Gertjan van Heijst			gertjan@swi.psy.uva.nl
Social Science Informatics
Department of Psychology
University of Amsterdam
Roetersstraat 15,
1018 WB Amsterdam
Netherlands
tel. (+31)-20-5256787
tel. (+31)-20-5256789 (secretariat)
fax. (+31)-20-5256896
--------------------------------------------------------------





----------------------8<--------------------8<---------------------------

(in-package "ONTOLINGUA-INTERNAL")


(defun define-theory-internal 
       (theory-name 
	included-theories 
	documentation
	initargs
	implementation
	io-package)
  "Builds or modifies an OntoLingua theory."
  (let* ((impl (validate-implementation 
		(if (consp implementation)
		    (first implementation)
		  implementation)))
	 (theory-class (theory-class (get impl 'implementation))))
    (when (record-source-file-name theory-name theory-class)
	  (when documentation
		(setf (documentation theory-name 'onto-theory) documentation))
	  (let* ((included-theories 
		  (included-theories-for-proper-implementation
 		    included-theories 
		    impl
		    theory-name))
		 (old-version (find-theory theory-name impl nil))
		 (new-version 
		  (implement-define-theory
		   (if old-version
		       (apply #'reinitialize-instance 
			      #-TI (if (eq theory-class
					   (class-name (class-of old-version)))
				       old-version
				     ;; Patched here by JPR because of LCL
				     ;; change-class bug.
				     (progn (change-class old-version
							  theory-class)
					    old-version))
			      #+TI old-version
			      :implementation impl
			      :included-theories included-theories
			      :io-package io-package
			      initargs)
		     (apply #'make-instance theory-class
			    :name theory-name
			    :implementation impl
			    :included-theories included-theories
			    :io-package io-package
			    initargs)))))
	    (loop for theory in (included-theories new-version) do
		  (pushnew new-version (including-theories theory)))
	    (pushnew new-version *all-theories*)
	    (setf (getf (get theory-name 'theory) impl) new-version)
	    (pushnew new-version (theories (get impl 'implementation)))
	    new-version))))



(defun included-theories-for-proper-implementation (included-theories
						    impl
						    theory-name)
  ;; first allow the implementation to do something to prevent
  ;; uninclusion
  (dolist (itheory-name included-theories)
	  (unless (find-theory itheory-name impl nil)
		  (implement-not-include-theory impl 
					      itheory-name 
					      itheory-name)))
  ;; then do the real work, this what ontolingua already did.
  (loop for itheory-name in included-theories 
	for theory = (find-theory itheory-name impl nil)
	if theory collect theory))



(defgeneric implement-not-include-theory (implementation 
					including-theory-name
					included-theory-name)
  (:documentation "IMPLEMENT-UNINCLUDE-THEORY Allows implementations
to do something when ontolonigua is about to uninclude
a theory with name <included-theory-name> that does not
exist for <implementation>."))


(defmethod implement-not-include-theory ((imp t) theory-name itheory-name)
  (warn bogus-include-warn-string theory-name itheory-name))



(defmethod implement-not-include-theory ((implementation (eql :workbench))
					 including-theory-name
					 included-theory-name)
  (declare (ignore including-theory-name))
  (autoload-theory-with-name included-theory-name))