Reflection and introspection

Pietro Braione schizophonic@tiscali.it
Sat, 9 Mar 2002 01:37:07 +0100


I will try to say a word or two on reflection 
and introspection. Hope it will be right, however 
there are many persons here who can correct
my statements if it will be the case. Anyway, 
I also hope it will not be too distant from 
correctness, or it would mean that I did not 
understand *anything* about reflection.

Reflection is the ability of a system to contain 
a representation of itself (better: a system is 
reflective if ...). Take this statement in a very 
wide sense, as a "representation of itself" may 
mean many things. For a computational system, 
it may mean a formal description of its 
virtual machine (an example: a quine, which is 
a program containing a representation of its 
source code), or - more complex but also more 
interesting - also a representation of the state of 
this machine as it runs. This means that the system 
must be able to encode using the abstractions it 
defines not only its code but also the state of 
computation: for a running - imperative - program, 
this means not only the source code, but also the 
content of all the variables, the procedure call stack 
and the next statement to execute. When a system 
is able to put all this data in, say, a variable at any 
time it executes (operation called reification) we 
say it can perform introspection as this data is made
available to inspect the system as it works. 
This is only one aspect of reflection. The other aspect 
is intercession, which happens when any modification 
to the variable containing the representation of the 
running program is reflected back in the running program 
itself. This closes the circle: the representation of 
the system is not only an independent snapshot, 
but it is causally connected to it: modifying the 
representation causes a corresponding modification 
to the system, and viceversa. So, reflection is not 
only introspection but also intercession: a reflective 
system should be able to reify itself, entering a state 
where it can exhamine its "self" by outside, modify 
it and reinstall the modified "self" - or make it 
available to another system for analysis and 
modification.

Pietro