[comp.lang.prolog] Tracking Interaction Histories

abbott@aerospace.aero.org (Russell J. Abbott) (08/19/89)

In article <56231@aerospace.AERO.ORG> I wrote:
> One feature I want to include in a browsing system I'm building is to
> let users capture, edit, and then replay sequences of browsing
> operations.  Is there a good way to do that in smalltalk?

This seems to be a special case of a more general problem.  I've also
been thinking about how to implement Prolog-like logical variables in
Smalltalk.  The obvious thing would be to define a class called Variable
with one instance variable for the variable's referenced value, if any.
The problem this raises is that one wants to be able to send to Variable
objects messages to be passed on to the variable's referent.  But in
order for the variable to be able to do that it has to have built into
it selectors for all the possible calls it's referents may ever receive,
which is impossible.  What is really needed is some sort of meta-method
that can handle any call.  But as far as I know, smalltalk doesn't
support such a thing.  (Is that true?  I'm really just a smalltalk
novice.)

One would need a similar capability if one wanted to write some sort of
interpreter which could accept any call at all.  If one had such an
interpreter one could build the history maintainer I asked for
originally.  How does the smalltalk world handle the need for this sort
of thing?-- 
-- Russ abbott@itro3.aero.org

arshad@lfcs.ed.ac.uk (Arshad Mahmood) (08/21/89)

In article <56248@aerospace.AERO.ORG> abbott@aero.UUCP (Russell J. Abbott) writes:
>In article <56231@aerospace.AERO.ORG> I wrote:
>> One feature I want to include in a browsing system I'm building is to
>> let users capture, edit, and then replay sequences of browsing
>> operations.  Is there a good way to do that in smalltalk?
>
>This seems to be a special case of a more general problem.  I've also
>been thinking about how to implement Prolog-like logical variables in
>Smalltalk.  The obvious thing would be to define a class called Variable
>with one instance variable for the variable's referenced value, if any.
>The problem this raises is that one wants to be able to send to Variable
>objects messages to be passed on to the variable's referent.  But in
>order for the variable to be able to do that it has to have built into
>it selectors for all the possible calls it's referents may ever receive,
>which is impossible.  What is really needed is some sort of meta-method
>that can handle any call.  But as far as I know, smalltalk doesn't
>support such a thing.  (Is that true?  I'm really just a smalltalk
>novice.)
>
>One would need a similar capability if one wanted to write some sort of
>interpreter which could accept any call at all.  If one had such an
>interpreter one could build the history maintainer I asked for
>originally.  How does the smalltalk world handle the need for this sort
>of thing?-- 
>-- Russ abbott@itro3.aero.org


Try trapping the message in Object.

doesNotUnderstand: aMessage 
	"First check for a compound selector.  If found, try copying down code
	into the receiver's class.  If this is unsuccessful,
	announce that the receiver does not understand the argument, aMessage,
	as a message.  The default behavior is to create a Notifier containing the 
	appropriate message and to allow the user to open a Debugger. 
	Subclasses can override this message in order to modify this behavior."
	| status gripe |

	status _ self class tryCopyingCodeFor: aMessage selector.
	status==#OK ifTrue:
		[^self perform: aMessage selector withArguments: aMessage arguments].

	gripe _ status==#HierarchyViolation
		ifTrue: [aMessage selector classPart , ' is not one of my superclasses: ']
		ifFalse: ['Message not understood: '].
	NotifierView
		openContext: thisContext
		label: gripe , aMessage selector
		contents: thisContext shortStack.
	"Try the message again if the programmer decides to proceed."
	^self perform: aMessage selector withArguments: aMessage arguments


------
	This is the method which notifies you of the fact that the message
	is not understood.

	The message itself is in aMessage and you can do pretyy much anything 
	you like with it.


	Hope this helps.

	Note: I have not had a chance to try this on our machines since
	they're rather heavily used, but there is no reason why
	this shouldn't work.

A. Mahmood
Laboratory for Foundations of Computer Science
Edinburgh University
Scotland
e-mail: arshad@lfcs.edinburgh.ac.uk

arshad@lfcs.ed.ac.uk (Arshad Mahmood) (08/21/89)

oops, he notices just after his sent it that some kind soul has answered the
same question on comp.land.smalltalk.

But since the prolog people may not read the smalltalk bb, it may still be
of minute use.

sorry.