Is there a Squeak3.x way to do "thisContext inquire"

Andreas Raab andreas.raab at gmx.de
Wed Apr 2 01:19:12 UTC 2003


> Can this be done in Squeak 3?

Easily. Here's a proof of concept:

ContextPart>>inquire: aSelector
	"Do 'context inquire message' using one-arg selector"
	| ctx rcvr failToken |
	"whatever, just unique"
	failToken := Object new.

	"search sender chain"
	ctx := thisContext.
	[ctx == nil] whileFalse:[

		"see if receiver understands it"
		rcvr := ctx receiver.
		(rcvr respondsTo: aSelector) ifTrue:[

			"send to receiver, see if it passes"
			result := [rcvr perform: aSelector] 
				on: InquiryPass 
				do:[:ex| ex return: failToken].

			"if it doesn't pass, answer result"
			result == failToken ifFalse:[^result].

		].

		"continue searching"
		ctx := ctx sender.
	].

	"ultimately signal InquiryFail"
	^InquiryFail signal

Of course, what you *need* this for entirely eludes me ;-)))

Cheers,
  - Andreas

> -----Original Message-----
> From: squeak-dev-bounces at lists.squeakfoundation.org 
> [mailto:squeak-dev-bounces at lists.squeakfoundation.org] On 
> Behalf Of Brian Keefer
> Sent: Wednesday, April 02, 2003 2:25 AM
> To: Squeak
> Subject: Is there a Squeak3.x way to do "thisContext inquire"
> 
> 
> >From deep within the VI4 swiki page..
> 
> 'thisContext inquire message' will search the sender chain 
> for the first
> receiver that understands message and send it to him. The receiver may
> choose to return a result or pass the inquiry by signaling 
> the InquiryPass
> notification. If he returns a result, the result will be the 
> result of the
> inquiry message. If he passes the inquiry, the search 
> continues with his
> senders. If the search exhausts without finding a responsible 
> receiver, an
> InquiryFail notification is raised, the default of which is 
> to do nothing
> and return nil as the result of the inquiry message.
> 
> Can this be done in Squeak 3?
> 



More information about the Squeak-dev mailing list