Poet2.2 Manual Prototype Object Extension for Tcl

Overview

Poet (Prototype Object Extension for Tcl) is an object-oriented programming (OOP) extension to the Tcl/Tk language that implements dynamic prototype inheritance.  Most OOP languages distinguish between objects and classes, prototype inheritance languages have only one construct: objects.  Prominent OOP languages that also use prototype inheritance are Self, JavaScript and NewtonScript.

The Poet library defines an object called Object, which is the ancestor of all Poet objects, and a set of methods for Object that are thus available to all objects in the system.  Object and about 40 of its methods are implemented in C, along with a constraint network (see below).  The remaining Object methods and a library of objects descending from Object are implemented in Tcl.  Most object definitions are dynamically loaded from the Poet library at runtime, when the object is first referenced.

All Poet objects (except Object) have one or more parent objects in an ordered list.  The first parent is the primary, the remaining parents provide multiple inheritance and are called mixins.  When a message is sent to an object, the system first checks to see if the object has a method for handling that message.  If not, the object's parents are searched, then the parents' parents, and so on up the inheritance hierarchy, until a method is found. Any object can become a parent, or prototype, for any number of descendant objects.

Poet objects may be made persistent by mixing in the object Thing. The application programmer uses the object ThingPool to specify the storage directory (or single file, using Metakit's VFS) and to open and close the pool.  All objects inheriting from Thing are written as Tcl source files when the pool is closed.  When the application is resumed and the ThingPool is opened, the persistent objects are loaded dynamically when they are first invoked, just like objects in the Poet library.

Poet objects may have any number of named slots which may contain any Tcl value.  Slots whose names begin with a "_" are considered private and are stored only on the local object.  All other slots are public.  When a public slot's value is requested and is not present on the current object, the object's inheritance hierarchy is searched for an object owning a slot of that name, in the same manner as when searching for a method. If the value of an inherited slot is changed, the object gets its own copy of the slot with the new value, while the ancestor that contained the slot retains the original value.

The value of a Poet slot may also be constrained by specifying a formula, in Tcl, that computes its value.  Any other slots referenced in the formula are added to the constrained slot's network, when their values change the value of the constrained slot will be updated. The satisfaction of a constraint can be suspended and later resumed, maintaining the liveness of the system.

In a process called assimilation, Poet uses Tk's introspection support to automatically generate Poet object definitions which encapsulate the Tk, Ttk, and BWidget widgets.  Some of these objects are extended with
additional handwritten Poet code that is preserved when a new version of Tk, Ttk, or BWidgets is assimilated.  Some additional widgets are provided, including an object inspector and a code editor with syntax highlighting.

Poetics (Poet Integrated Construction Set) is a sub-project within Poet to create tools to allow a Poet application's code and user interface to be modified by the end-user, from within the Poet application. Analogous to the way in which a Tcl application programmer may expose the Tcl interpreter to the end-user and thus create an application that can be customized at the command level, a Poet application programer may expose Poetics to the end-user and allow customization at the user interface level.  The object inspector
and code editor are the beginnings of the Poetics toolset.   Poetics is not ready for end-user use (a more extensive Poetics toolset will be part of Poet version 3) so it is not enabled by default. However, it can be very useful for the Poet application programmer as a means to inspect and modify their Poet application while it is in development.