ObjectScript ルーチン
ここでは、簡単ですが重要な ObjectScript ルーチンについて学習します。ここをクリックすると、詳細な説明が表示されます。このルーチンでは、直角三角形の両辺の長さを元に面積と斜辺を計算します。では、見てみましょう。
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>
ObjectScript が、Basic や Java などの他の言語と非常に類似していることがわかります。この例には、ルーチンの "メイン" セクションのほかにユーザ定義関数の $$IsNegative、プロシージャの Compute があります。また、Write、Read、Set、Do、Quit の各コマンド、If/Else、Do/While の各文、後置条件文、$Justify、$Extract、$Case、$Zsqr の各関数の例も含まれています。
次ページから、コマンド、文、関数の詳細について学習します。