A ObjectScript Routine
Let's start by taking a look at a simple, yet nontrivial ObjectScript routine. Click here to see it. It computes the area and hypotenuse of a right triangle, given the lengths of the two sides. Let's run it:
SAMPLES>do ^RightTriangle Compute the area and hypotenuse of a right triangle given the lengths of its two sides. First, choose a unit of measurement. (i)nches, (f)eet, (m)iles, (c)entimeters, m(e)ters, (k)ilometers: i Length of side 1: 3 Accepted. Length of side 2: 4 Accepted. The area of this triangle is 6.00 square inches. The hypotenuse is 5.00 inches. Current date: Feb 25 2011 Current time: 2:42 PM SAMPLES>
You'll notice that ObjectScript looks a lot like other languages, such as Basic and Java. Besides the "main" section of the routine, $$IsNegative is an example of a User-Defined Function, and Compute is an example of a Procedure. There are examples of the Write, Read, Set, Do, and Quit commands; If/Else and Do/While constructs; post-conditionals; and $Justify, $Extract, $Case, and $Zsqr functions.
Next, we'll start to cover each command, construct, and function in more detail.