defstruct and :named
Hello all,
I'm just wondering about the behavior of defstruct I'm observing.
I was reading the HyperSpec on defstruct and noticed :named option, which
can be used when a :type is also specified. For instance, (from the
hyperspec:)
" (defstruct (binop (:type list) :named)
(operator '? :type symbol)
operand-1
operand-2) => BINOP
(make-binop :operator '+ :operand-1 'x :operand-2 5) => (BINOP + X 5)
(make-binop :operand-2 4 :operator '*) => (BINOP * NIL 4)"
because the :named option was specified, and the type of the
structure is a list, the first element of the list is BINOP. Now type
checking can be done. The spec says:
"For structures defined with a :type option, type-of returns a type
specifier such as list or (vector t), depending on the type supplied
to the :type option. The structure name does not become a valid type
specifier. However, if the :named option is also supplied, then the
first component of the structure (as created by a defstruct
constructor function) always contains the structure name. This allows
the structure name to be recovered from an instance of the structure
and allows a reasonable predicate for the conceptual type to be
defined: the automatically defined name-p predicate for the structure
operates by first checking that its argument is of the proper type
(list, (vector t), or whatever) and then checking whether the first
component contains the appropriate type name."
However, I notice the constructor I get when using defstruct is a little odd:
(defstruct (foo (:type list) :named)
slot1
slot2)
And now if I type "(make-foo" and get the lambda-list (Ctrl-Shift-A) I see
(Make-Foo &Key (T1 (Quote Foo)) Slot1 Slot2)
which seems as though it has a keyword for the type that probably shouldn't
be there. In fact :
(make-foo :t1 'bar)
=> (Bar Nil Nil)
so of course
(foo-p (make-foo :t1 'bar))
=> Nil
It would seem to be a bug, as if I have more defstructs, they have
a different keyword argument for the type. E.g. If I evaluate the
defstruct again, the lambda list for make-foo becomes
(Make-Foo &Key (T2 (Quote Foo)) Slot1 Slot2)
Am I right that this behavior isn't what's expected?
--
=====================
Joshua Taylor
tayloj@rpi.edu