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

Question about methods

   Redistributed: commonloops.pa
   Date: Wed, 3 Jan 90 14:02:27 -0500
   From: Arun Welch <welch@cis.ohio-state.edu>

   Given a method, I'd like to put a wrapper on it such that the result
   of calling the method is printed out to *trace-output*. This is
   analogous to giving an after advice to a function (at least in the
   lisps I'm familiar with). Is there some way for an after method to get
   the results of the previous computation, or is the right way to do it
   to use an around method as follows:

   (defmethod foo :around ((bar some-object))
	   (prog ((result (call-next-method)))
		   (print result *trace-output*)

   The behaviour I'm looking for would be analogous to

   (advise foo :after '(print value *trace-output*))


In general the closest thing to "the right thing" would probably be:

(defmethod foo :around ((bar some-object))
  (let ((results (multiple-value-list (call-next-method))))
    (print (car results) *trace-output*)
    ;; and anything else you want with results
    (values-list results)))

This is not perfect because FOO may already have an :AROUND method for

If you know FOO on SOME-OBJECT *ALWAYS* returns one value then your
definition will work. 

This is kind of a drag because it clearly conses.