Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!usc!trwind!gumby!wiley!alice.coyote.trw.com!scott From: scott@alice.coyote.trw.com (Scott Simpson) Newsgroups: comp.lang.lisp Subject: Re: CLOS questions Summary: Create a new class Keywords: classes, discriminated records, public domain CLOS Message-ID: <2726886C.2C1B@wilbur.coyote.trw.com> Date: 25 Oct 90 06:38:36 GMT References: <28175@bellcore.bellcore.com> Sender: news@wilbur.coyote.trw.com (News Software) Organization: TRW Inc., Redondo Beach, CA Lines: 72 In article <28175@bellcore.bellcore.com> dsm@ctt.bellcore.com (David S. Miller) writes: >I'm thinking of using CLOS to implement a project, and I have a few >(1) Are there any public domain (ftp'able) versions of CLOS out there? >(for a Sun 3)? PCL (Portable Common Loops) from arisia.xerox.com. I believe it is very close to standard CLOS. >(2) Is it possible for an object to be an instance of two disjoint classes? Not that I know of. >(e.g.) Supposing I have classes representing groups of people such as >employees, students, and athletes. What if I want to represent an individual >student-employee, or student-athlete, without creating a new class? Why don't you want to create a new class? Assuming that employees, students and athletes are all disjoint, you could have a hierarchy like person | ------------------------------------------------------ / | \ employee student athlete \ | \ / | \ | ----------------------- | \ | | | \ | student-athlete | ---------------- | | \ | | \ | / \ | ----------- student-employee-athlete / >As far as I can tell, it doesn't seem possible for an object to be an >instance of more than one class. Yet, it seems inappropriate to have >to create a new class every time you want a new instance to inherit >attributes from more than one existing class. You can inherit attributes from more than one class by using multiple inheritance. You still have to create a new class to do multiple inheritance though. Why is creating a new class inappropriate? >(3) Is there any mechanism in CLOS for automatically classifying an >object into a class based on attribute values? > >(e.g.) In the previous example, suppose the 'student' class has an >"athletic-prowess' slot. If the value of that slot was set to 'high >for a particular instance, then I'd want that instance to be >classified into the 'athlete' class as well. Why couldn't you write a routine to take a parameter that is the athletic-prowess? You then compute on this parameter and create either a student or athlete object and return it. Athlete would inherit from student and student would contain the athletic-prowess slot. >The best way that I can think of to handle this is to define a method >such as: >(defmethod (setf athletic-prowess) ((new-value (eql 'high)) ...) > ...classify this instance as an athlete... ) The problem is that you want to reclassify an object after creation time. The only way I know of doing this is to create a brand new object in a different class. If you didn't create a brand new object, then anybody pointing to the old object would suddenly be pointing to a new object of a different type! Ada has this problem with dynamically allocated discriminated record types. Consequently, in Ada, you cannot change the discriminant after the record is dynamically allocated. -- Scott Simpson TRW scott@coyote.trw.com