[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


    Date: 17 Aug 90 18:33:41 GMT
    From: Andre de Souza Mello Valente <USERASMV%LNCC.BITNET@Forsythe.Stanford.EDU>

       c) How can I create the new versions of typep, type-of,
       etc., using the older ones? I tried to create a new
       package and shadow the CL ones, but had no success. BTW, I
       tried the same with print, but got nothing also.

If the intent is to modify the behavior of these functions for
only those programs which use your system, then the
new-package/shadow/redefine steps should work okay.  (Assuming
the programs which use your system now call your functions; which
can be realized more or less transparently through some
appropriate combination of package-use'ng, shadow'ng and/or

If the intent is to modify the behavior for all callers of these
"redefined" functions then I know of at least a couple of

First, if your CL implementation provides an ADVICE facility then
I'd suggest using that to modify the behavior of functions whose
definition you have no control over.  Of the CL implementations I
have used (TI, Symbolics, Franz Allegro, & Lucid), they all have
an ADVICE facility.  I don't know about GHCL.

Alternatively, you could use the poor man's route via storing the
function objects of the functions you want modified and then use
your code to define a new definition for the lisp:<function-name>
symbol.  This is the technique utilized by the Express Windows

For example, something like this might work:

(lisp:make-package :my-package :use '(lisp))

(in-package :my-package)

(defparameter *shadowed-functions* '(typep ... <other shadow'd functions>)) 

(shadow *shadowed-functions* :my-package)

(defun my-typep (object type)
  <your code here>)

(defun typep (object type)
  (or (lisp-typep object type)
      (my-typep object type)))

 Other similar redefinitons ...

(defun setup-lisp-functions (functions)
  (dolist (function functions)
    (let ((local-name (intern (concatenate 'STRING "LISP-" (symbol-name function))))
	  (new-function (intern (symbol-name function)))
	  (cl-function function))
      (unless (fboundp local-name)
	(setf (symbol-function local-name) (symbol-function cl-function)))
      (when (fboundp new-function)
	(setf (symbol-function cl-function) (symbol-function new-function))))))

(setup-lisp-functions *shadowed-functions*)

Care must be taken with this approach.  If you, say, get a patch
from your CL vendor for one of the "redefined" functions, you'll
have to reinstall your modification.  I always felt uneasy about
this approach, although I'm not sure why.  I'm never quite sure
how this affects the rest of the CL system for other things (like
TRACE, for instance).  Perhaps others more knowledgeable can comment
on the implications and possible risks.

Stephen L. Nicoud  <snicoud@atc.boeing.com>  uw-beaver!bcsaic!snicoud
Boeing Advanced Technology Center for Computer Sciences