Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!ucsd!ucbvax!hplabs!hplabsz!mayer From: mayer@hplabsz.HPL.HP.COM (Niels Mayer) Newsgroups: comp.lang.lisp.x Subject: Re: A few questions from a hacker. Message-ID: <5870@hplabsz.HPL.HP.COM> Date: 31 Aug 90 00:26:54 GMT References: <1990Aug27.001721.9563@comp.vuw.ac.nz> <5854@hplabsz.HPL.HP.COM> Reply-To: mayer@hplabs.hp.com (Niels Mayer) Organization: Hewlett-Packard Labs, Software & Systems Lab, Palo Alto, CA. Lines: 103 Summary: Expires: Sender: Followup-To: In article L.Parkes@comp.vuw.ac.nz (Lloyd Parkes) writes: >The code in 2.1 only searches the instance variables of the class for >which the method is defined, not the object that is being sent the >message. This only crops up when you are playing around with super >classes and inheritance of methods. What I was doing was trying to >write a generic `set an instance variable' method for an entire class >heirarchy. After I had `fixed' xlisp, wasn't very difficult, just >yucky :-) I guess I misunderstood what you meant in your prev posting. In Xlisp, Instance variables are part of an object instance; methods can access instance variables of their class, and their superclasses; you send messages to objects, and methods defined on the class or superclasses "answer" the message... If you are expecting methods on superclasses to be able to access instance variables defined on subclasses, then you are not using the Xlisp object system "correctly"... maybe you need to be using a more complex object system (e.g. CLOS) for the kind of things you are doing. The following code works in the version of XLISP I'm using in Winterp-1.01 (which uses a modified XLISP 2.1): | (setq class-0 | (send Class :new | '(ivar-0) ;new instance vars | )) | | (setq class-1 | (send Class :new | '(ivar-1) ;new instance vars | '() ;no class vars | class-0)) ;superclass | | (setq class-2 | (send Class :new | '(ivar-2) ;new instance vars | '() ;no class vars | class-1)) ;superclass | | (setq class-3 | (send Class :new | '(ivar-3) ;new instance vars | '() ;no class vars | class-2)) ;superclass | | (send class-3 :answer :printout '() | '( | (format T " ivar-0=~A\n ivar-1=~A\n ivar-2=~A\n ivar-3=~A\n" | ivar-0 ivar-1 ivar-2 ivar-3) | )) | | (send class-3 :answer :isnew '(v0 v1 v2 v3) | '( | (setq ivar-0 v0) | (setq ivar-1 v1) | (setq ivar-2 v2) | (setq ivar-3 v3) | )) | | (setq inst0 | (send class-3 :new 'just 'say 'no "to bugs") | ) | (setq inst1 | (send class-3 :new 'means 'fight 'a "war on bugs") | ) | (setq inst2 | (send class-3 :new 'if 'panama 'was "a police action") | ) | (setq inst3 | (send class-3 :new 'why 'do 'they "call it a war on drugs?") | ) | | (send inst0 :printout) | (send inst1 :printout) | (send inst2 :printout) | (send inst3 :printout) The four :printout message-sends at the end give the following results... : Xlisp-Eval-Result: ivar-0=JUST : ivar-1=SAY : ivar-2=NO : ivar-3=to bugs : Xlisp-Eval-Result: ivar-0=MEANS : ivar-1=FIGHT : ivar-2=A : ivar-3=war on bugs : Xlisp-Eval-Result: ivar-0=IF : ivar-1=PANAMA : ivar-2=WAS : ivar-3=a police action : Xlisp-Eval-Result: ivar-0=WHY : ivar-1=DO : ivar-2=THEY : ivar-3=call it a war on drugs? ------------------------------------------------------------------------------- Niels Mayer -- hplabs!mayer -- mayer@hplabs.hp.com Human-Computer Interaction Department Hewlett-Packard Laboratories Palo Alto, CA. *