[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
overloading defstruct accessors
The following example can be viewed as an attempt to overload the
accessor function "get-a" by making it access the "get-a" fields of
both a "foo" structure and a "bar" structure.
(defstruct (foo (:conc-name ())) get-a)
(defstruct (bar (:conc-name ()) (:include foo)) get-b)
(setq afoo (make-foo :get-a 1))
(setq abar (make-bar :get-a 2 :get-b 3))
One could argue that the second defstruct redefines the accessor
function "get-a" so that it will only work on bar-s. On the other
hand, it is relatively easy to implement this so that "get-a" will
work both on foos and bars.
Xerox Common Lisp (Lyric release) objects to
by complaining that "afoo is not a bar". Franz Allegro Common Lisp
allows it. I haven't tried any other lisps.
Is there a consensus on what an implementation of Common Lisp should
do with this?
P.S. Please, no complaints about the stylistic appropriateness of
using (:conc-name nil) in this way. This was written by someone who
should be using CLOS.