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

uses of call-next-method



I hate to post what seems to be a simple question, but I must be
missing something. I would appreciate anyone's comments on this.

I want to define a method which uses a preexisting less specific
method using call-next-method. A simple example is:

(defclass position () ((x :initform 0 :type number) 
				  (y :initform 0 :type number)))

(defmethod move ((point position) dx dy)
	(with-slots (point)
		(setf x (+ x dx) y (+ y dy)))
	point)

(defclass 3d-position (position) ((z :initform 0 
							 :type number)))

; and now, define a version of 3d-move which uses the 2d move

(defmethod move ((point 3d-position) dx dy dz)
	(with-slots (point) 
		(setf z (+ z dz))
		(call-next-method)))

This doesn't work because it passes three arguments to the
(move (position)) method when only two are expected.

I know that the example is silly, but there must be a way to do this.
Any suggestions?
------------
In the Xerox version of PCL, I can define all of the above and then do

	(setq foo (make-instance 'position))
	(move foo 1 1 1)

and I won't get an error, UNTIL I try running

	(setq bar (make-instance '3d-position))
	(move bar 1 1 1)

Once this fails, calls to

	(move foo 1 1 1) 

will also fail (too many arguments).
I don't know how any other versions of PCL behave.