Reflectionï
Logtalk provides support for both structural and behavioral reflection. Structural reflection supports computations over an application structure. Behavioral reflection supports computations over what an application does while running. The structural and behavioral reflection APIs are used by all the developer tools, which are regular applications.
Structural reflectionï
Structural reflection allows querying the properties of objects, categories, protocols, and predicates. This API provides two views on the structure of an application: a transparent-box view and a black-box view, described next.
Transparent-box viewï
The transparent-box view provides a structural view of the contents and properties of entities, predicates, and source files akin to accessing the corresponding source code. I.e. this is the view we use when asking questions such as: What predicates are declared in this protocol? Which predicates are called by this predicate? Where are clauses for this multifile predicate defined?
For entities, built-in predicates are provided for enumerating entities, enumerating entity properties (including entity declared, defined, called, and updated predicates; i.e. full predicate cross-referencing data), and enumerating entity relations (for full entity cross-referencing data). For a detailed description of the supported entity properties, see the sections on object properties, protocol properties, and category properties. For examples of querying entity relations, see the sections on object relations, protocol relations, and category relations.
Note
Some entity and predicate properties are only available when the source files are compiled with the source_data flag turned on.
The logtalk built-in object provides predicates for querying loaded source files and their properties.
Black-box viewï
The black-box view provides a view that takes into account entity encapsulation and thus only allows querying about predicates and operators that are within the scope of the entity calling the reflection methods. This is the view we use when asking questions such as: What messages can be sent to this object?
Built-in methods are provided for querying the predicates that are declared and can be called or used as messages and for querying the predicate properties. It is also possible to enumerate entity operators. See the sections on finding declared predicates and on predicate properties for more details.
Behavioral reflectionï
Behavioral reflection provides insight on what an application does when running. Specifically, by observing and acting on the messages being exchanged between objects. See the section on event-driven programming for details. There is also a dependents library that provides an implementation of Smalltalk dependents mechanism.
For use in debugging tools, there is also a small reflection API providing trace and debug event predicates provided by the logtalk built-in object.