What is Topcameleon ?

Topcameleon is a Gtk2 graphical interface for the OCaml toplevel. Like the text mode toplevel, it permits interactive use of the Objective Caml system through a read-eval-print loop. Some additional functionalities are provided:

  • saving the input code into a file,
  • viewing and browsing of computed values in a tree-oriented view,
  • easy access to definitions of values, modules, types, ....

One can also create his own graphical toplevel with the tool cam-mktop2.


Topcameleon is launched by the following command:

topcameleon [options] [object-files] [source-file]

The options are the same as the OCaml toplevel, and files in arguments are handled the same way, except that if a source file is given, Topcameleon does not exit after having evaluated the code in this file, but rather shows the main window with the code in the file still present like if the user had typed it. This way, you can type your code after the loaded code, and when you're satisfied you can save the whole code in one file (by default it is saved in the given source file). So topcameleon cannot be used as a script interpreter, but it was not developed for such a purpose.

Using Topcameleon

On the Topcameleon main window, the left pane contains a list of the defined elements (values, types, modules, ...). The second pane shows the selected value, in a tree-oriented way. The right pane is the console, with the result on top and the input text at the bottom. The "Execute" button executes the code in the input widget.

Each time you define a new element, it is added to the list of elements. When you select an element is this list, its value is shown (if it is a value) in the 'tree view', and the result box jumps to its definition so you can see how it was defined.

Errors in the input field are hilighted when you execute a phrase (do not forget the ";;" at the end of your phrases).

You can use the "File/Load file ...", "File/Save" and "File/Save as ..." menus to load and save files. Note that the current file you're using is displayed in the title bar. It is the file your code will be saved into if you use the "File/Save" menu.

The "File/Preferences" menu opens the configuration window where you can change the style scheme and choose whether the values in the tree are automatically expanded or not (default is true, but it can take some time and memory for very large values).

Creating a graphical toplevel with cam-mktop2

As for the OCaml toplevel, you have a command which lets you define your own graphical toplevel. This command is cam-mktop2 and is used the same way as the ocamlmktop command (see the OCaml manual for more information). The only differences are:

  • you get a graphical toplevel instead of a text one,
  • it already contains the following libraries: Unix, LablGtk, Lablglade, Config_file, Configwin, Gmylist, Okey, Lablgtksourceview2, Custop.