Content deleted Content added
m →Language: <source lang="ada"> |
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags |
||
Line 36:
The [[Hello World]] program in XL looks like the following:
<
use XL.TEXT_IO
WriteLn "Hello World"
</syntaxhighlight>
An alternative form in a style more suitable for large-scale programs would be:
Line 97:
===Type system===
XL1 type checking is [[data type|static]], with [[generic programming]] abilities that are beyond those of languages like Ada or C++. Types like arrays or pointers, which are primitive in languages like C++, are declared in the library in XL. For instance, a one-dimensional array type could be defined as follows:
<
generic [Item : type; Size : integer] type array
</syntaxhighlight>
A ''validated generic type'' is a generic type where a condition indicates how the type can be used. Such types need not have generic parameters. For instance, one can declare that a type is <code>ordered</code> if it has a less-than operator as follows:
Line 115:
This also applies to generic types that have parameters, such as <code>array</code>. A function computing the sum of the elements in any array can be written as follows:
<
function Sum(A : array) return array.Item is
for I in 0..array.Size-1 loop
result += A[I]
</syntaxhighlight>
===Type-safe variable argument lists===
Line 138:
===Expression reduction: operator overloading===
Operators can be defined using the <code>written</code> form of function declarations. Below is the code that would declare the addition of integers:
<
function Add(X, Y: integer) return integer written X+Y
</syntaxhighlight>
Such ''written forms'' can have more than two parameters. For instance, a matrix linear transform can be written as:
<
function Linear(A, B, C : matrix) return matrix written A+B*C
</syntaxhighlight>
A written form can use constants, and such a form is more specialized than a form without constants. For example:
<
function Equal(A, B : matrix) return boolean written A=B
function IsNull(A : matrix) return boolean written A=0
function IsUnity(A : matrix) return boolean written A=1
</syntaxhighlight>
The mechanism is used to implement all basic operators. An expression is progressively reduced to function calls using written forms. For that reason, the mechanism is referred to as ''expression reduction'' rather than operator overloading.
Line 193:
This mechanism is used to implement standard notations:
<
if true then TrueBody else FalseBody -> TrueBody
if false then TrueBody else FalseBody -> FalseBody
</syntaxhighlight>
The XL programming language uses a programming approach focusing on how ''concepts'', that live in the programmer's mind, translate into ''representations'' that are found in the [[machine code|code]] space.
|