Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!newsfeed.internetmci.com!chi-news.cic.net!nntp.coast.net!torn!nott!cunews!dbuck
From: dbuck@superior.carleton.ca (Dave Buck)
Subject: Re: beginner question
X-Nntp-Posting-Host: superior.carleton.ca
Message-ID: <DJysFG.uA@cunews.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Organization: Carleton University, Ottawa, Canada
References: <4bc64r$hkl@lfsserv1.fsc.ibm.com> <4bchop$1473@watnews2.watson.ibm.com>
Date: Fri, 22 Dec 1995 01:35:40 GMT
Lines: 65

In article <4bchop$1473@watnews2.watson.ibm.com>,
David N. Smith  <dnsmith@watson.ibm.com> wrote:
>In article <4bc64r$hkl@lfsserv1.fsc.ibm.com> Bill Majoros,
>majorosw@inetgw.fsc.ibm.com writes:
>>I am a little surprised at how the 'super' keyword works in Gnu Smalltalk
>>inside instance methods.  If I send a message to super, the super-class
>>handles it.  But if I pass super to another method, it becomes indistinguishable
>>from self; polymorphism is not inhibited in the usual way.  Is this how other
>>Smalltalk systems work?
>
>
>I presume you mean something like this. 
>
>In a class named Child we have the methods:
>
>   method1
>      self askIt: super
>      
>   method2
>      self askIt: self
>   
>   askIt: anObject
>      anObject foobar
>   
>   foobar
>      ^ 1
>      
>In its parent class, Parent:
>
>   foobar
>      ^ 2
> 
>Then, the question is what does this expression answer:
>
>   Child new method1

It returns "a Child".  Trick question. :-)

Ok, now, suppose we change the above methods to actually return their
results.  In that case, Child new method1 returns 1.  The only time
'super' is different than 'self' is when it's followed by a message
name.  If it's stored into a variable or passed as a parameter, super
is identical to self.

(I almost hate to do this:)
From "Smalltalk-80 the Language and its Implementation" (p. 64)
The use of super as other than a receiver (for example, as an
argument), has not different effect from using self; the use of super
only affects the initial class in which the messages are looked up.

Incidently, super's can't be cascaded either.  eg:
   super test1; test2

is equivalent to:
   super test1. self test2.


David Buck
dbuck@ccs.carleton.ca

_________________________________
| David K. Buck                 |
| dbuck@ccs.carleton.ca         |
| The Object People             |
|_______________________________|
