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

generic constructor functions

Is there any reason not to have class constructor functions be generic
functions?  I'd like to be able to do something like:

  (defclass device () (viewports ...) (:constructor make-device))
  (defclass viewport () (device ...)
    (:constructor make-viewport ((device device) ...)))
  (defclass X-device (device) (display ...) (:constructor make-X-device))
  (defclass X-viewport (viewport) ()
    (:constructor make-viewport ((device X-device) ...)))

instead of something like:

  (defclass device ()
    ((viewport-constructor 'make-generic-viewport)
     viewports ...)
    (:constructor make-device))
  (defclass viewport () (device ...)
    (:constructor make-generic-viewport))
  (defmethod make-viewport ((device device) &rest args)
    (apply (viewport-constructor device) args))
  (defclass X-device (device)
    ((viewport-constructor 'make-X-viewport)
     display ...)
    (:constructor make-X-device))
  (defclass X-viewport (viewport) ()
    (:constructor make-X-viewport))

The only advantage that I can think of having constructors be standard
functions is speed and I think that the advantages of having them be
generic functions out-weigh that consideration.