hi i have a few questions:
1.i'm working on a database, and i'm storing objects in different hashtables. each object must be able to give a list of other objects that belong to it(i put a slot in each class for this) , for example the object "Computer Science"(class 'major') must have the list of all the students of this major (class 'student'). now my question: is it better to put the objects('students' for exmaple) directly on a list, or put only their keys (the reference in the hashtable) on the list?
Or,generaly does it take a lot of memory if we store already existing objects on a list, or does it only make new pointers on the same (eq) objects?
2.can we give an object as an optional argument to a generic function(and a method), if yes how?
3.how can i define a new slot (in a new file) for an already existing class, defined in another file?
looking forward your answers
and
thank U
Fabien Baldacci wrote:
> hi i have a few questions:
>
> 1.i'm working on a database, and i'm storing objects in different hashtables. each object must be able to give a list of other objects that belong to it(i put a slot in each class for this) , for example the object "Computer Science"(class 'major') must have the list of all the students of this major (class 'student'). now my question: is it better to put the objects('students' for exmaple) directly on a list, or put only their keys (the reference in the hashtable) on the list?
> Or,generaly does it take a lot of memory if we store already existing objects on a list, or does it only make new pointers on the same (eq) objects?
Without further information, I'd say it's better to store the existing
objects. It's right that only references to those objects are stored -
unlike C++ and like Java, CLOS never makes implicit copies of objects.
> 2.can we give an object as an optional argument to a generic function(and a method), if yes how?
Yes, like any optional arguments to non-generic functions. Note however,
that all methods for a generic function need to be "congruent", i.e. in
the case of optional arguments, all need to have the same number of
optional arguments. Furthermore, only methods can provide default
values, and method dispatch cannot take optional arguments into account,
unless you fiddle with the MOP.
See 7.6 of the HyperSpec on generic functions and methods. You might
also consult a tutorial on CLOS.
> 3.how can i define a new slot (in a new file) for an already existing class, defined in another file?
Simple, just repeat the definiton with your slot added. So if the
original definition is thus:
(defclass person ()
name address)
...and you want to add a slot for age, just include the following in
your program:
(defclass person ()
name address age)
CLOS takes care of updating already existing instances of the class. You
only have to make sure that your definition comes after (or instead of)
the original one.
BTW, it isn't a problem to repeat the definition of a slot from a
superclass. If you have the following additional class definition:
(defclass student (person)
enrollment age)
...the class STUDENT will in fact have only one slot AGE. This might
come in handy if you want to make sure that each class from a
third-party source has a specific field without needing to change the
inheritance structure.
All the best,
Pascal
--
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
Pascal Costanza <········@web.de> writes:
> Furthermore, only methods can provide default values, and
> method dispatch cannot take optional arguments into account,
> unless you fiddle with the MOP.
It is probably easier to have a separate non-generic function
handle the optional arguments, like DESCRIBE does for
DESCRIBE-OBJECT.