[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [KAHLE@Aquinas.Think.COM: defstruct request for common lisp]
I wish there were a function like:
that returns the list of slots of a defstruct.
One idea that's been discussed that would do what you want, in
fact do something more general, is to redefine structures in terms
of object-oriented programming, if and after CLOS is accepted as
part of ...
What useful things could one do with the output of (structure-slots
<structure-name>), given that the choice of slot to access cannot be
gracefully deferred until run-time the way p-lists allow? I'm afraid
that a "structure-slots" function wouldn't be all that valuable because
of this deeper limitation of structures.
I'm not knocking structures though. The no-free-lunch rule indicates
that if one wants such dynamic slot selection then there will be a price
to pay at run-time.
What this points out is the current lack of a data structure in CL that
provides a fixed number of named slots AND run-time choice of slot to
access. Perhaps the following table (off the top of my keyboard) can
highlight the characteristics of CL's data structures and the (missing)
functionality that objects will add to the language. This should
graphically reinforce your point that the needs that Brewster Kahle
originally had in mind might be properly addressed only by CLOS
Some Common Lisp Data Structures and their usage
Arrays Structures P-Lists A-Lists | Objects?
access * |
access * * * | *
Fixed # |
of "slots" * * | *
labels (1) * * * | *
update * * * (2) | *
(1) The name of the slot to be accessed can be determined at run-time
(impossible with structures, barring some horrible kludge)
(2) Possible but the general case is more trouble than with P-Lists,
(setf (getf plist key) newvalue) suffices for old OR NEW keys.