Previous Home Contents Next

Chapter 3: Language orientation

3.1 Traditional and nontraditional aspects

3.2 Expressions and evaluation

3.3 Functions

3.4 Domains

3.5 Compilation

3.6 Libraries



3.1 : Traditional and nontraditional aspects

In many regards, Aldor is a very conventional programming language:

It is possible to transliterate most programs written in languages such as C, C++, Fortran or Lisp almost directly into Aldor.

In other regards, Aldor is somewhat unconventional:

Some of these language aspects, when taken together and handled uniformly, have particularly powerful interactions.

We give one example: Since types are first class values, functions may take types as parameters and return types. Let us call such a type-to-type function a ``functor.'' Since functions are first class, so are these functors. Therefore it is possible to write programs which manipulate functors. A functor-manipulating program is discussed in
section 23.9: Swap.

Programs such as these may used to reorganize levels in type towers -- for instance, to make the dynamic choice to convert values in the type

to values in the type


3.2 : Expressions and evaluations

An Aldor program consists of a set of expressions representing a computation to be performed. Performing the computation is called evaluation or execution and produces a set of values.
Each value has an associated type, which dictates how the value is to be represented in computer memory. Expression evaluation may cause other actions beyond producing values. These additional actions are called side-effects and include things such as output and modifying the values stored in computer memory.

The syntax of the language allows larger expressions to be built up from smaller ones. The evaluation of an expression may involve the evaluation of some or all of its subexpressions, and its value can be formed using the values of the subexpressions.

Elements such as ifs, loops, and function forms are all expressions in Aldor. This contrasts with some other languages, such as C or Fortran, where they are special ``statements'' which can only appear in limited contexts.

The rules of the Aldor programming language ensure that, in a well-formed program, all the values potentially produced by any given expression have the same type. This has two consequences: it allows programs to be transformed to faster, equivalent code, by avoiding type tests during execution, and, more importantly, it allows a common class of programming errors to be detected immediately.

We say the Aldor programming language is expression based and statically typed.


3.3 : Functions

Functions are treated as values in the same way as integers, lists or floating point numbers. The language provides mechanisms for composing and manipulating functions in useful ways, incorporating them in other data structures, or returning them as results.

Functions may depend on values defined externally to them so the act of dynamically creating a new function value captures the creation environment, forming what is normally called a closure.


3.4 : Domains

Often, several functions operate within a common environment. For this reason, in Aldor, an environment is called a domain of computation, or domain for short. Environments are essentially dictionaries which tie names to values. The language allows environments to be created and manipulated dynamically, and these form the basis for abstract types, packages, and objects as first-class values.

The language provides general mechanisms to allow new types to be used in all the same ways as built in types: they may provide the same sort of literal constants, participate in the same control structures, admit the same optimizations, etc. To ensure this equal status, the built-in types make use of the same general mechanisms to provide their function.

This has had two consequences: first, the extension mechanisms are pervasive and powerful; second, the language itself has very little built in. The language provides a minimal set of primitive types and operations. These are combined and extended in standard base libraries to provide a rich set of facilities.


3.5 : Compilation

Normally, evaluation does not directly use the source form of the expressions in a program. Rather, the evaluation is usually effected by first translating the source expressions to an equivalent set of lower-level instructions more suitable for the target environment. This is the job of the compiler. The result of the translation is a program which produces the same values and side-effects as the original program, but which might otherwise be represented very differently.


3.6 : Libraries

Aldor is geared to developing and using combinations of libraries. Certain properties of the language have therefore been oriented to controlling the dependencies and interactions among libraries of programs.

A source program can see only the declared public behaviour of the files it uses.

A compiled program can depend on the private behaviour of the files it uses, but only when given explicit permission to do so. It is up to the client to decide whether it is willing to become dependent on the private behaviour of the provider.

In practice, this permission amounts to increased scope for optimization. In no case does it allow a source-level dependency.


Previous Home Contents Next