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

Parallel/Similar Flavors



;;; What I want is to be able to define two top-level flavors that
;;; differ *only* in a macro that is written in (or near) their
;;; respective base flavors.  I.e. the macro expansion in an
;;; intermediate flavor should depend on *complete* definition of the
;;; top-level flavor.
'
;;; As an example considering the following:

;;; I have a FROB object which is an instance of a large, hairy
;;; flavor.  It has an instance-variable SWITCH? that turn off parts
;;; of the functionality of the Frob.  Now the stuff that this Switch
;;; affects is used all over the place, so I want it to be fast and
;;; clean (hence the macro).

;;; Basic Flavor that allows Switching.
(DEFFLAVOR BASIC-SWITCHABLE-FROB ((SWITCH?))
	   ())

(DEFMETHOD (:SET-SWITCH BASIC-SWITCHABLE-FROB) (ON?)
  (SETQ SWITCH? ON?))

(DEFMACRO-IN-FLAVOR (WHEN-SWITCH BASIC-SWITCHABLE-FROB) (&BODY BODY)
  `(WHEN SWITCH?
     ,@BODY))

;;; Mid-level mixin that uses the Switch.
(DEFFLAVOR INTERMEDIATE-FROB-MIXIN ()
	   ()
  (:REQUIRED-FLAVORS BASIC-SWITCHABLE-FROB))

(DEFMETHOD (:FROBIZE INTERMEDIATE-FROB-MIXIN) ()
  (PRINT "FROB1")
  (WHEN-SWITCH
    (PRINT "FROB2")))

;;; Complete, usable FROB flavor (with Switch)
(DEFFLAVOR FULLBLOWN-SWITCHABLE-FROB ()
	   (INTERMEDIATE-FROB-MIXIN
	    BASIC-SWITCHABLE-FROB))

;;; OK; So far so good.

;;; Now, in certain applications of FROBS, I know that I will *never*
;;; want the Switch to be off and, because this is used a lot, I want
;;; to avoid the when-branch.  In particular, I want to the
;;; WHEN-SWITCH macro to act as a No-op (i.e. so that I can leave its
;;; many calls in place).
;;;
;;; I.e., what I would *like* to be able to do is to define a
;;; base-flavor like the following:
(DEFFLAVOR BASIC-NON-SWITCHABLE-FROB ()
	   ())

(DEFMACRO-IN-FLAVOR (WHEN-SWITCH BASIC-NON-SWITCHABLE-FROB) (&BODY BODY)
  `(PROGN
     ,@BODY))

;;; This would allow me to write the non-switchable top-level flavor
;;; (which uses the common, intermediate flavor INTERMEDIATE-FROB-MIXIN).
(DEFFLAVOR FULLBLOWN-NON-SWITCHABLE-FROB ()
	   (INTERMEDIATE-FROB-MIXIN
	    BASIC-NON-SWITCHABLE-FROB))

;;; But this loses because the WHEN-SWITCH in the :FROBIZE method gets
;;; the wrong macro definition.  (Juggling the :REQUIRED-METHODS and
;;; changing the flavor dependencies just moves the basic problem
;;; somewhere else.)
;;; 
;;; (Now, clearly this is a toy case, but for a real object I'd want
;;; the common intermediate mixins to call --some version of-- the
;;; WHEN-SWITCH macro, without their definitions being changed.)
;;; 
;;; The only (brute-force) way I can figure to do this is to define
;;; two complete, parallel *identical* (except for their names) sets
;;; of mixins.

;;; Suggestions?

;;; Thanks
;;; NICHAEL