make-instance :around

From: Gabor Melis (mega_at_hotpop.com)
Date: 05/21/04


Date: 21 May 2004 13:52:37 -0700

I'm trying to intercept make-instance calls for the user class but the
around method with the (eql 'user) specializer is not getting called
under some circumstances (see below). It is under CMUCL. Clisp does
OK.

(defclass user ()
  ())

(defmethod make-instance :around ((class (eql 'user)) &rest args)
  (declare (ignorable class args))
  (format t "AROUND/EQL-USER-SYMBOL~%")
  (force-output)
  (call-next-method))

(defmethod make-instance :around ((class (eql (find-class 'user)))
&rest args)
  (declare (ignorable class args))
  (format t "AROUND/EQL-USER-CLASS~%")
  (force-output)
  (call-next-method))

(defun make/symbol ()
  (make-instance 'user))

(defun make/class ()
  (make-instance (find-class 'user)))

(make/symbol)
;; when make/symbol is compiled it prints nothing
;; when make/symbol is not compiled it prints:
;; AROUND/EQL-USER-SYMBOL
(make/class)
;; prints:
;; AROUND/EQL-USER-SYMBOL

;; doing essentially the same with another method works
(defmethod gfun ((s (eql 'user)) &rest args)
  (declare (ignore s args))
  (format t "GFUN PRIMARY~%"))

(defmethod gfun :around ((s (eql 'user)) &rest args)
  (declare (ignore s args))
  (format t "GFUN AROUND/EQL-USER-SYMBOL~%")
  (force-output)
  (call-next-method))

(defun bar ()
  (gfun 'user))

(bar)
;; prints:
;; GFUN AROUND/EQL-USER-SYMBOL
;; GFUN PRIMARY