I've got a Lisp library with a structure 'problem'.
I want to do the following:
(defstructure (pop-problem
(:include problem)
(:constructor create-pop-problem)))
But besides this, I also want to add an extra slot to my pop-problem.
According to http://defstruct, I understand this should be:
(defstructure (pop-problem
(:include problem (possible-ops :initform NIL))
(:constructor create-pop-problem)))
But this doesn't seem to work.
Lieven wrote:
> I've got a Lisp library with a structure 'problem'.
> I want to do the following:
>
> (defstructure (pop-problem
> (:include problem)
> (:constructor create-pop-problem)))
>
> But besides this, I also want to add an extra slot to my pop-problem.
> According to http://defstruct, I understand this should be:
>
> (defstructure (pop-problem
> (:include problem (possible-ops :initform NIL))
> (:constructor create-pop-problem)))
>
> But this doesn't seem to work.
In Common Lisp, it's DEFSTRUCT, not DEFSTRUCTURE, and there's
no :INITFORM keyword. Moreover, putting slots there is just to
override slot properties of inherited slots. New slots go a level
up, after the (pop-problem ...) list:
(defstruct (pop-problem (:include problem) (:constructor create-pop-problem))
(possible-ops nil))
Paul
In article <························@news.skynet.be>,
Lieven <···············@hotmail.com> wrote:
> I've got a Lisp library with a structure 'problem'.
> I want to do the following:
>
> (defstructure (pop-problem
> (:include problem)
> (:constructor create-pop-problem)))
How does your DEFSTRUCTURE macro relate to the standard DEFSTRUCT macro?
>
> But besides this, I also want to add an extra slot to my pop-problem.
> According to http://defstruct, I understand this should be:
>
> (defstructure (pop-problem
> (:include problem (possible-ops :initform NIL))
> (:constructor create-pop-problem)))
>
> But this doesn't seem to work.
That syntax is used to modify the slot options of slots that are
inherited. If you want to add additional slots, you do that in the body
of the DEFSTRUCT:
(defstruct (pop-problem
(:include problem)
(:constructor create-pop-problem))
(possible-ops nil))
Also, the initial value of a slot is not specifies using :INITFORM
(that's the DEFCLASS syntax), it's done simply by putting the initial
value after the slot name, as shown above. Keyworded slot options
follow that -- the only standard ones are :TYPE and :READ-ONLY.
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***