Type-Definition Object Will Duquette ABSTRACT The dominant Tcl object paradigm is "objects are ensemble commands". However, the call-by-name semantics associated with this paradigm are not always appropriate. Type-definition objects provide a simple way to combine complex object behavior with call-by-value semantics. A type-definition object is an ensemble command which defines the operations available for a type whose values are represented as standard Tcl values. Operations include creating new values, modifying values, querying values, conversion of values from other types, and so forth. A type-definition object can be a singleton, as in a "matrix" command which defines a variety of operations on general matrices represented as lists-of-lists; the Tcl 8.5 "dict" command and the family of "list" commands can be regarded as examples of type definition singletons. Type-definition objects can be also be parameterized instances of a class of type definitions; objects of this kind can define ranged numeric types, enumerations, and other constrained types. This paper presents a number of type definition objects implemented for the Joint Asymmetric Warfare Simulation (JAWS). SUMMARY The dominant Tcl object paradigm, exemplified by Tk, Incr Tcl, and Snit, is "objects are ensemble commands". An object is represented as a Tcl ensemble command; the object's methods are the command's subcommands. Objects defined in this way have many nice properties, especially the ability to be passed and referenced by name. Ensemble commands are inconveniently heavy-weight when the object will serve primarily as a container for data, and especially when call-by-value semantics are desired. Ensemble commands are not reference counted, and must be destroyed explicitly when the object is no longer needed. For data objects, a straightforward representation as a scalar value or list is usually preferable. In this case, a type-definition ensemble can be defined; the Tcl 8.5 "dict" command is a perfect example. The string representation of a dictionary is a list of keys and values. The "dict" command allows the programmer to manipulate dictionaries in a variety of ways; an implementation in which the dictionaries were represented as ensemble commands rather than values would be much less useful. A type-definition ensemble can itself be a member of some class, and can thus define values of a parameterized type. As a simple example, a Snit object with -min and -max options could define a range of integers or real numbers. Type-definition objects, whether singletons like "dict" or members of a class, encapsulate the knowledge needed to manipulate a class of Tcl values in a convenient package which is easily used throughout the modules of an application, whether imported as a command or passed by name as an argument or option value. The Joint Asymmetric Warfare Simulation (JAWS) is a new training simulation now under development as part of the Army Constructive Training Federation (ACTF). JAWS is being implemented largely in Tcl, and includes a number of type-definition objects, including matrices, vectors, enumerations, and quality variables. An enumeration is a mapping from a list of names to the integers 0,...,n-1; a quality is an enumeration whose elements represent arbitrary numeric values within some numeric range. The full paper would amplify on the points made above, and then go on to describe these type-definition objects in more detail.