[Openmcl-devel] CLOS make-instance :around behaviour

Bob Hutchison hutch-lists at recursive.ca
Sun Oct 19 11:53:50 PDT 2008


Hi,

(This is all os x 10.5.5, and "Clozure Common Lisp Version 1.2-r10552   
(DarwinX8664)")

Here is a small bit of lisp that illustrates, what I think, is  
peculiar behaviour:

(defclass some-class ()
   ((state :initform "NOT INITIALISED" :accessor state)))

(defmethod print-object ((self some-class) out)
     (print-unreadable-object (self out :type t :identity t)
           (format out "[state ~S]"  (state self))))

(defmethod make-instance :around ((class (eql 'some-class)) &rest  
initargs)
   (format t "make instance around...~%")
   (let ((pxo (call-next-method)))
     (format t "  the instance is ~A~%" pxo)
     (setf (state pxo) "INITIALISED")
     pxo))

(defun make-some-class()
   (make-instance 'some-class))


Now, from the repl:

? (make-instance 'some-class)
make instance around...
   the instance is #<SOME-CLASS [state "NOT INITIALISED"]  
#x300040D164DD>
#<SOME-CLASS [state "INITIALISED"] #x300040D164DD>
? (make-some-class)
#<SOME-CLASS [state "NOT INITIALISED"] #x300040D1647D>


So, if you call make-instance directly from the repl, the make- 
instance :around method is called. If you call the function make-some- 
class it is not called. This is true for sbcl as well. However,  
lispworks and clisp call make-instance :around in both cases.

The behaviour of clozure and sbcl does not make a lot of sense to me.

Help!

Thanks,
Bob

P.S. I'll ask on the sbcl list as well




More information about the Openmcl-devel mailing list