Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!fas-news.harvard.edu!newspump.wustl.edu!news.starnet.net!wupost!howland.reston.ans.net!vixen.cso.uiuc.edu!uwm.edu!lll-winken.llnl.gov!decwrl!pa.dec.com!acm.org!jan.bytesmiths
From: jan.bytesmiths@acm.org
Message-ID: <9502180140.AA10390@Newbridge.COM>
Subject: Re: Accessing sender
Organization: Bytesmiths, a technical services company
Reply-To: jan.bytesmiths@acm.org
Date: Fri, 17 Feb 1995 20:47:52 -0500
X-Received: by usenet.pa.dec.com; id AA07023; Fri, 17 Feb 95 17:50:31 -0800
X-Received: by pobox1.pa.dec.com; id AA25367; Fri, 17 Feb 95 17:50:29 -0800
X-Received: from Newbridge.COM by inet-gw-3.pa.dec.com (5.65/10Aug94)
	id AA00505; Fri, 17 Feb 95 17:48:46 -0800
X-Received: from Newbridge.COM ([138.120.100.14]) by nbkanata.Newbridge.COM (4.1/SMI-4.1)
	id AA29923; Fri, 17 Feb 95 20:40:51 EST
X-Received: from 138.120.62.109 (shfpt52_9) by Newbridge.COM (4.1/SMI-4.0)
	id AA10390; Fri, 17 Feb 95 20:40:22 EST
X-To: comp.lang.smalltalk.usenet@decwrl.dec.com
X-References: <3h8586$dn7@epsilon.qmw.ac.uk> <mohr.792449032@parcplace.com>
Lines: 51

In article <mohr.792449032@parcplace.com>, mohr@parcplace.com wrote:

> johnsam@dcs.qmw.ac.uk (John Samuel) writes:
> 
> >Is there any way to access the sender of a message, without suspending 
> >the current process and looking at its context ? 
> 
> 1. Use 'thisContext', an obscure pseudo-variable which always refers 
>    to the current context. That is, say "thisContext sender
>    receiver". 
> 
> But...
> 
> 2. I'd recommend against #1.

But...

It is INCREDIBLY useful when used with discretion and the full knowledge
of its cost.

>    Using 'thisContext' breaks the implicit (but obviously not 
>    enforced) notion that a given method's behavior is fully 
>    determined by its receiver, parameters, and perhaps some 
>    global state...

But that is a fairly limiting view of the world. Ever look at a return
address on an envelope? Wonder why "caller ID" is selling like hotcakes?
Why is email so easy to reply to? "It depends on the context..."

On the other hand, I do agree that code you are in charge of should take
pains to avoid using "thisContext" such as through adding arguments, etc.

On the other hand, what happens when you inspect the following and click
on "self":

   | a |
   a := Array new: 1.
   a at: 1 put: a.
   a

Well, in many dialects, you simply crash. However, by adding

   thisContext isRecursive ifTrue: [^self]

at the beginning of #printOn:, you avoid all those nasty crashes. (The
implementation of #isRecursive is left as an exercise to the reader,
because I have to go home to watch the X-Files now...)

 Jan Steinman, Bytesmiths <jan.bytesmiths@acm.org>
 2002 Parkside Court, West Linn, OR 97068-2767 USA, +1 503 657 7703
 1025 Grenon #1002, Ottawa, Ontario K2B 8S5 Canada, +1 613 820 9919
