[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
defstruct slot names
I hope this wasn't discussed in the distant past.
The CLTL definition of the defstruct macro (p.308) has a hole which
deserves plugging. Each slot-name in the defstruct form is required
only to be a symbol. It would seem that the following is perfectly
legal, even if it has no clear motivation:
(defstruct automobile
engine:horsepower
insurance:dollar-value)
It is reasonable to assume that the constructor function can only
ignore the package of a slot-name regardless whether it is the same
package as the structure name. So this is OK:
(make-automobile :horsepower 289 :dollar-value 14500)
Anyway, this is probably what would happen in any obvious implementation
which had given this issue no thought at all. But consider:
(defstruct automobile
engine:horsepower
liability-insurance:dollar-value
collision-insurance:dollar-value)
While there is no requirement that slot-names be distinct, it is
reasonable that identical slot names should be an error. But the two
dollar-value slots are distinct even though they herniate the naming
scheme for constructor keywords and access-functions. The problem is
that slot names are semantically scoped within the structure containing
them, so packages are irrelevant. The ways in which slot names are used
rather assumes this, but the assumption is nowhere explicit.
Can anyone think of a legitimate use for packages in slots names? If
not, I propose the manual should explicitly state that defstruct interns
all slot names in the keyword package. Compare the definition of the
#S(name slot1 'value ...) reader syntax (p.357).
This issue will likely also affect active objects.