I have to particular generic functions in my program which
very often need to both be called in succession and occasionally
called seperately. They are named LEFT-INSTANCES and RIGHT-INSTANCES.
I often do something like the following
(loop for fun in (list #'left-instances #'right-instances)
when (funcall fun some-obj)
collect something...)
however when i try to put the list of the two functions
into a constant list, might it be that the compiler
get confused? I.e., Is the function re-calculated
everytime i add a method to the generic function?
And does that make my list invalid?
(defgeneric left-instances (blah))
(defgeneric right-instances (blah))
(defconstant *funs* (list #'left-instances #'right-instances))
(defmethod left-instances ((blah some-class))
...)
(defmethod right-instances ((blah some-other-class))
..)
(defclass some-class ()
(( right
:accessor right-instances)))
Is this a bad idea? I.e., to put #'left-instances and #'right instances
into a list, then add methods later on?
-jim
From: Wade Humeniuk
Subject: Re: function binding and discriminating function
Date:
Message-ID: <pA_Yd.38177$gJ3.3954@clgrps13>
Jim Newton wrote:
> I have to particular generic functions in my program which
> very often need to both be called in succession and occasionally
> called seperately. They are named LEFT-INSTANCES and RIGHT-INSTANCES.
>
> I often do something like the following
>
> (loop for fun in (list #'left-instances #'right-instances)
> when (funcall fun some-obj)
> collect something...)
>
> however when i try to put the list of the two functions
> into a constant list, might it be that the compiler
> get confused? I.e., Is the function re-calculated
> everytime i add a method to the generic function?
> And does that make my list invalid?
>
No. The functions in the list are the generic functions, not the
specific methods.
Personally I would use a macro like the following instead of
using loop.
(defmacro collect-left-then-right (obj left-body right-body)
`(nconc (when (left-instances ,obj) (list ,left-body))
(when (right-instances ,obj) (list ,right-body))))
Wade