plist structure clos object
printable-readably x x -
O(1) access - x* x
adding slots cons - with mop
functional shadowing cons - with a meta-class
method dispatching cons structure class
*: with pure structures, or structures implemented as vector.
Since you need a textual representation for editing, you could use
as well plists or structures:
#S(citation
:author "…"
:title "…"
…)
CLOS objects would need more work to provide an printable-readbly
format, but it can be simple enough to do:
(apply (function make-instance) 'citation (read stream))
Note, you can also do something similar for structures:
(apply (function make-citation) (read stream))
Slot accesses are faster with structures and objects, but with less than
5 slots, it won't make a lot of difference. Locallity may be better
with structures and objects than with lists too.
Adding slots at run-time is not possible with structures. This may also
be a problem if you have to support different versions of files. With
CLOS object it's simple enough to do with MOP. With plist, it's
trivial: (list* :new-field new-value old-plist).
Functional shadowing (ie. "modifying" a field of a structure as a
functional data structure), is not possible with structures, trivial
with plist (list* :old-field new-value old-plist), and doable with MOP,
defining a meta-class.
Plist may also have an advantage in a situation where the set of fields
may change from object to object (eg. if there are a lot of optional
fields), but this can also be dealt with subclasses (both for CLOS
objects and for structures) if that granularity correspond to the
problem.
If you want to write methods specific to your entities, then plist are
as cons cells, and you can distinguish them from other kind of lists,
while dispatching on a structure or clos class is trivial.
So, there's nothing unidiomatic. Unless you have other reasons to
choose to define citations as CLOS classes (you may very well have, I
imagine citations of books would differ from citations of articles would
differ from citations of movies, etc), I often find more practical to
use structure than plist in my programs. You could still easily keep
the plist format for the human editable files.
In any case this should not be a problem to switch from one to the
other, since you are using functional abstractions.
--
__Pascal Bourguignon__
http://www.informatimago.com/
A bad day in () is better than a good day in {}.