Go to the first, previous, next, last section, table of contents.


Introduction

TOM is an object oriented programming language. The following example shows the famous `hello world' program, this time written in TOM.

 1  implementation class HelloWorld: stdio
 2  
 3  int
 4    main Array arguments
 5  {
 6    [[out print "Hello, world!"] nl];
 7  
 8    = 0;
 9  }
10  
11  end;
12
13 implementation instance HelloWorld end;

In line 1, a class is defined with the name HelloWorld. It inherits from stdio, implying that anything defined by the stdio class is directly available.

Line 2 is empty. That's ok, as empty lines have no significance.

From line 3 to 9, a method is defined. This method is named main; it accepts one argument, named arguments, the type of which is Array; it returns an int.

The main method, when implemented by a class, is special as it is the method invoked when the program is started. The arguments argument is an array of strings holding the command line arguments to the program. main returns an int which will be the exit value of the program.

In line 6, two methods are invoked. Invoking a method is the same as sending a message. The first invocation send a message print to the object known as out. out is a variable inherited from stdio; it is the `standard output' stream of the program, known as stdout in C. The print message has one argument, a string containing `Hello, world!'.

By convention, every print method implemented by a stream returns the receiver, so that the invocation itself can be used as the receiver of another message to the stream. In this case, the argument-less message nl is sent. This causes a new line to be output to the standard output stream, and that stream to be flushed to make sure any buffered contents will be displayed on the user's terminal. nl also returns the receiver, but that value is ignored.

In line 8, the assignment of 0 with an empty left-hand-side sets the value to be returned from this method. It returns 0, a value which indicates success. Note that this form of the return value assignment does not actually cause an immediate return from this method (it would if the = were replaced by return).

By the end in line 11, the definition of the HelloWorld class is finished. In line 13, the instances of the HelloWorld class are defined. Since we never allocate HelloWorld instances, this definition is rather empty.

So much for an easy introduction. The rest of this document will be more of a reference manual, with not that many elaborate examples.


Go to the first, previous, next, last section, table of contents.