Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsfeed.cit.cornell.edu!newsstand.cit.cornell.edu!news.kei.com!newsfeed.internetmci.com!in2.uu.net!utcsri!utnut!torn!nott!cunews!tina.mrco.carleton.ca!knight
From: knight@mrco.carleton.ca (Alan Knight)
Subject: Re: How private are private methods?
X-Nntp-Posting-Host: tina.mrco.carleton.ca
Message-ID: <knight.815285250@tina.mrco.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Reply-To: knight@mrco.carleton.ca (Alan Knight)
Organization: The Object People
References: <46tftq$h0k@watnews2.watson.ibm.com> <476oae$nma@newsbf02.news.aol.com>
Date: Thu, 2 Nov 1995 04:07:30 GMT
Lines: 37

In <476oae$nma@newsbf02.news.aol.com> bytesmiths@aol.com (Bytesmiths) writes:
>In Smalltalks that support a REAL CONTEXT OBJECT (just want to make sure
>Jeff's keyword filter catches this message :-) you can do:

>privatePlease

>    thisContext sender receiver == self ifFalse: [^self error: 'Hey, I''m
>private!'].
>    self privateStuff

...
>Sorry David -- your Smalltalk can't do either of these things!

Hmmmm.

	| myProcess frame result |
	myProcess := Processor activeProcess.
	result := OrderedCollection new.
	1 to: 5 do: [:i |
		 result add: (myProcess stackAtFrame: i offset: -3)].
	^result

This gets me the sender (and its senders) just fine. Granted, it's not
quite as pretty as the DarkPlace version, and if you're doing it on
your own process you have to be quite careful about where in the stack
you're doing it for, but it does work (and since I don't think it's
reifying anything it may even be more practical). By the way, this
code expects to be in a method, and it starts by giving you the sender
of that method. In practice you probably want frame 2.

I'd have to think about conditional compilation :-)

-- 
 Alan Knight                | The Object People
 knight@acm.org             | Smalltalk and OO Training and Consulting
 alan_knight@mindlink.bc.ca | 509-885 Meadowlands Dr.
 +1 613 225 8812            | Ottawa, Canada, K2C 3N2
