# OTcl - MIT Object Tcl

## The FAQ & Manual (Version 0.96, September 95)

## What is OTcl?

OTcl, short for MIT Object Tcl, is an extension to Tcl/Tk for object-oriented programming. It shouldn't be confused with the IXI Object Tcl extension by Dean Sheenan. (Sorry, but we both like the name and have been using it for a while.)

Some of OTcl's features as compared to alternatives are:

- designed to be dynamically extensible, like Tcl, from the ground up
- builds on Tcl syntax and concepts rather than importing another language
- compact yet powerful object programming system (draws on CLOS, Smalltalk, and Self)
- fairly portable implementation (2000 lines of C, without core hacks)

OTcl was presented at the Tcl/Tk Workshop '95. It constitutes a standalone release of a system that has been in use, embedded in the VuSystem, for two years. We made the release public (with free use, distribution and modification under the MIT license) to meet the demand for object-oriented programming in Tcl.

## Where do I get it?

The primary distribution site for OTcl, including this FAQ and Manual, and documentation is:

> ftp://ftp.tns.lcs.mit.edu/pub/otcl/

As well as the source code distribution, binary distributions are available for some platforms.

## How do I make it?

OTcl is known to work with Tcl/Tk versions 7.3/3.6, 7.4/4.0, and 7.5/4.1 (alpha1) on Unix platforms. Since it is written in ANSI C, does not change the Tcl core, and is small, it should be relatively easy to port to other platforms. [And I expect it could easily work with earlier Tcl/Tk versions, at least down to 7.0/3.3.]

### Compiling the Source Distribution

To build OTcl from its source distribution, you will need access to the Tcl source distribution, plus compatible Tcl/Tk libraries and external includes. The Tcl source is needed to include structures defined in internal headers. The libraries are needed if you want to link OTcl into standalone shells.

(Specifically, OTcl needs the file tclInt.h and tclIntDecls.h from the source code to Tcl. If you're building OTcl on a platform with a binary installation of Tcl/Tk you must get these header files from the matching source code for your version ot Tcl/Tk.)

To compile, `cd` to the untarred directory, type `./configure`, and then `make`. The configuration process will ask you the location of the Tcl/Tk files it requires and produce the `Makefile`. Running `make` will cause four binaries to be produced; they are described below.

Don't be put off by the use of configure. Compiling OTcl is straightforward (it's all in one C file!) and configure is mainly being used to accommodate platform dependent libraries and linking. You can edit the `Makefile` directly, or issue compile and link commands manually.

### Using and Installing the Binaries

OTcl compiles to four binary results, each suited to a different purpose.

1. otclsh, a tclsh loaded with OTcl.
2. owish, a wish loaded with OTcl.
3. libotcl.a, the OTcl library, for adding OTcl to your Tcl application. See below.
4. libotcl.so (suffix may vary), a shared version of the OTcl library for dynamically loading OTcl into running Tcl shells. See below.

You can test the binaries with `make test`. This runs the `test.tcl` script, which should report that several tests are passed.

You can install the binaries with `make install`.

### Adding OTcl to Your Application

OTcl doesn't change the core, so it can be added to other Tcl applications or shells in the usual manner. It is known to work with expect-5.18 and tclX7.4a, for example. However, OTcl does depend on several internal Tcl data structures, so it may not be compatible with Tcl versions in which the core has been modified.

With a Tcl application of version 7.5 or higher (and a corresponding `libotcl.so`) OTcl may be loaded dynamically by issuing the tcl command `"load libotcl.so OTcl"` to the running interpreter. (If `libotcl.so` is not installed, then you may require environment variables, such as LD_LIBRARY_PATH for Solaris, or other schemes for access.)

Alternatively, OTcl can be linked into a Tcl application to provide access to its C API. Simply call `Otcl_Init` from your application initialization routine (for which you will need to include `otcl.h` and link against an OTcl library). Then your modules may acess OTcl C functions through its external interface file, `otcl.h`.

## How do I use it?

There's a quickstart tutorial to help you become familiar with OTcl syntax and style. It's included in the distribution.

> Tutorial

For documentation about objects, classes, and their capabilities, see the following reference pages. They're included in the distribution.

> OTcl Objects
> OTcl Classes
> OTcl Autoloading
> OTcl C API

You can read further about OTcl's capabilities and design in the workshop paper, also included as part of the distribution. It provides a couple of terse examples too.

> Extending Tcl for Dynamic Object-Oriented Programming
> David Wetherall and Christopher J. Lindblad
> Proceedings of the Tcl/Tk Workshop '95, Toronto, July 1995.

## Feedback?

Let me (djw@lcs.mit.edu) know if you have suggestions or other feedback.