Thanks for the quick reply.
Ramarren wrote:My suggestion would be to put class definitions in a different file than DEFCONSTANT.
I thought about doing this, but I only considered having a single constants file, which would have a circular dependency problem (i.e. normally the constants file would be the file all others depend on, but in this case it
depends on other files). I suppose I could make a special "view-constants" file. I think I'll try that. Good suggestion.
Use DEFINE-CONSTANT from Alexandria
with a proper test to resolve this.
I looked into using it, but I saw several strong arguments against doing so (e.g. it makes defconstant equivalent to defparameter, it doesn't work in certain cases anyway, etc.).
Ramarren wrote:But, in general, using DEFCONSTANT with anything else than characters, symbols or numbers is pointless. Just use DEFPARAMETER, there will be no difference, since object instances can't be inlined anyway, and they are not really constant anyway (DEFCONSTANT doesn't give any guarantees that the internal state of the object would not change).
Fair argument. I guess I wanted to use constant so they can be + variables instead of * variables (i.e. seeing +html-view+ defined with defparameter instead of defconstant might seem odd, no?) since the code would never change them.
Also, why is +html-view+ in the example given even a class? You can specialize methods on symbols with EQL specializers, like this:
- Code: Select all
(defgeneric render (component view))
(defmethod render ((component standard-object) (view (eql 'html-view)))
(defun test-it ()
(render (make-instance 'web-page) 'html-view))
html-view is a class and can have it's own slots and specializers. At this early stage nothing has been added to it, but there will be.