Article View: comp.lang.clos
Article #639method definition question
From: Alan Ruttenberg
Date: Mon, 17 Jun 1991 18:08
Date: Mon, 17 Jun 1991 18:08
40 lines
1481 bytes
1481 bytes
I have a question concerning creating a method applicable to one of two classes. Suppose I have two classes A and B. These two classes are distinct. They happen to share similar instance variables, but it is not possible to factor this out to a mixin, since I can't redefine A. I want to write a method which is applicable to either. The cleanest way to express it is: (deftype C () '(or A B)) (defmethod common ((instance C)) ...) This doesn't work. (can't find class C) My only two choices seem to be to either replicate the code, or to factor the body of the definition of common into a defun which is called by both. 1- (defmethod common ((instance A)) the code) (defmethod common ((instance B)) the same code) 2- (defmethod common ((instance A)) (the-code instance)) (defmethod common ((instance B)) (the-code instance)) (defun the-code (instance) the code) So the question is... Is there a more elegant way to do this? -alan
Technical Details
Message-ID:
<ALANR.91Jun17130803@chopin.media-lab.media.mit.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!news.media.mit.edu!news.media.mit.edu!alanrShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!news.media.mit.edu!news.media.mit.edu!alanr From: alanr@chopin.media-lab.media.mit.edu (Alan Ruttenberg) Newsgroups: comp.lang.clos Subject: method definition question Message-ID: <ALANR.91Jun17130803@chopin.media-lab.media.mit.edu> Date: 17 Jun 91 18:08:03 GMT Sender: news@news.media.mit.edu (USENET News System) Organization: MIT Media Laboratory Lines: 40