[hunchentoot-devel] Subclassing ACCEPTOR

Hi list, (make-package :vhost :use '(:common-lisp)) ;;; => #<PACKAGE "VHOST"> (in-package :vhost) (defclass vhost (tbnl:acceptor) ((tbnl::name :initform (error "Please give this VHOST a meaningful name.")))) ;;; => #<STANDARD-CLASS VHOST> (describe 'vhost) ;;; => VHOST::VHOST ;;; [symbol] ;;; ;;; VHOST names the standard-class #<STANDARD-CLASS VHOST>: ;;; Class precedence-list: VHOST, HUNCHENTOOT:ACCEPTOR, STANDARD-OBJECT, ;;; SB-PCL::SLOT-OBJECT, T ;;; Direct superclasses: HUNCHENTOOT:ACCEPTOR ;;; No subclasses. ;;; Direct slots: ;;; HUNCHENTOOT::NAME ;;; Initform: (ERROR "A virtual host must have a meaningful name.") (defvar *vhost1* (make-instance 'vhost)) ;;; => *VHOST1* <--- WHY NO ERROR ??? (describe *vhost1*) ;;; => #<VHOST (host *, port 80)> ;;; [standard-object] ;;; ;;; Slots with :INSTANCE allocation: ;;; PORT = 80 ;;; ADDRESS = NIL ;;; NAME = #:G1150 <--- this is what I want to prevent ;;; [...] Practical Common Lisp - page 214: "... if multiple classes specify an initform the new class uses the one from the most specific class. This allows a subclass to specify a different default value than the one it would otherwise inherit." What am I doing wrong here? Sebastian -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap

Sebastian, the acceptor class has a :default-initargs clause, so the :initform that you've provided is never being looked at. Use a :default-initargs in your vhost class to override the inherited :name initarg. -Hans On Mon, Dec 12, 2011 at 3:07 PM, Sebastian Tennant <sebyte@smolny.plus.com> wrote:
Hi list,
(make-package :vhost :use '(:common-lisp)) ;;; => #<PACKAGE "VHOST">
(in-package :vhost)
(defclass vhost (tbnl:acceptor) ((tbnl::name :initform (error "Please give this VHOST a meaningful name.")))) ;;; => #<STANDARD-CLASS VHOST>
(describe 'vhost) ;;; => VHOST::VHOST ;;; [symbol] ;;; ;;; VHOST names the standard-class #<STANDARD-CLASS VHOST>: ;;; Class precedence-list: VHOST, HUNCHENTOOT:ACCEPTOR, STANDARD-OBJECT, ;;; SB-PCL::SLOT-OBJECT, T ;;; Direct superclasses: HUNCHENTOOT:ACCEPTOR ;;; No subclasses. ;;; Direct slots: ;;; HUNCHENTOOT::NAME ;;; Initform: (ERROR "A virtual host must have a meaningful name.")
(defvar *vhost1* (make-instance 'vhost)) ;;; => *VHOST1* <--- WHY NO ERROR ???
(describe *vhost1*) ;;; => #<VHOST (host *, port 80)> ;;; [standard-object] ;;; ;;; Slots with :INSTANCE allocation: ;;; PORT = 80 ;;; ADDRESS = NIL ;;; NAME = #:G1150 <--- this is what I want to prevent ;;; [...]
Practical Common Lisp - page 214:
"... if multiple classes specify an initform the new class uses the one from the most specific class. This allows a subclass to specify a different default value than the one it would otherwise inherit."
What am I doing wrong here?
Sebastian -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap
_______________________________________________ tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel

Quoth Hans Hübner <hans.huebner@gmail.com>:
the acceptor class has a :default-initargs clause, so the :initform that you've provided is never being looked at. Use a :default-initargs in your vhost class to override the inherited :name initarg.
Ah. I see. I didn't think that would make any difference. This seems a little restrictive/clumsy to me. Is there a way of telling whether or not a superclass uses a :default-initargs clause without looking at the source? DESCRIBE doesn't help. Trial and error I suppose. Thanks by the way. Sebastian -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap

On Mon, Dec 12, 2011 at 4:13 PM, Sebastian Tennant <sebyte@smolny.plus.com> wrote:
This seems a little restrictive/clumsy to me. Is there a way of telling whether or not a superclass uses a :default-initargs clause without looking at the source? DESCRIBE doesn't help. Trial and error I suppose.
None that I knew of. I tend to not use :initform for slots that are initialized by make-instance arguments. But that is just a matter of style and preference. -Hans
participants (2)
-
Hans Hübner
-
Sebastian Tennant