Information Technology Reference
In-Depth Information
i:= 1;
ordered := TRUE;
WHILE i < n AND ordered DO
ordered := ordered AND (a[i] <= a[i+1]);
i:=i+1
END;
In
Alma-0
we can just write:
ordered := FOR i:= 1 TO n-1 DO a[i] <= a[i+1] END
This is much simpler and as ecient. In fact, this use of the FOR statement
corresponds to the bounded universal quantication and the above one line pro-
gram equals the problem specication.
In the logic programming framework there are no arrays. But the related
problem of nding whether a list L is ordered is solved by the following program
which is certainly more involved than the above one line of
Alma-0
code:
ordered([]).
ordered([X]).
ordered([X, Y | Xs]) :- X =< Y, ordered([Y| Xs]).
1.3
Towards an Imperative Constraint Programming Language
In
each variable is originally uninitialized and needs to be initialized
before being used. Otherwise a run-time error arises. The use of uninitialized
variables makes it possible to use a single program for a number of purposes,
such as computing a solution, completing a partial solution, and testing a can-
didate solution. On the other hand, it also provides a limitation on the resulting
programming style as several rst-order formulas, when translated to
Alma-0
Alma-0
syntax, yield programs that terminate in a run-time error.
With the addition of constraints this complication would be overcome. The
idea is that the constraints encountered during the program execution are moved
to the constraint store and evaluated later, when more information is available.
Then the above restriction that each variable has to be initialized before being
used can be lifted, at least for the variables that are manipulated by means of
constraints. Additionally, more programs can be written in a declarative way. In
fact, as we shall see, an addition of constraints to
leads to a very natural
style of programming in which the constraint generation part of the program is
often almost identical to the problem specication.
Constraint programming in a nutshell consists of generating constraints (re-
quirements) and solving them by general and domain specic methods. This
approach to programming was successfully realized in a number of programming
languages, notably constraint logic programming languages.
Up to now, the most successful approach to imperative constraint program-
ming is the object-oriented approach taken by ILOG Solver (see [16], [9]). In this
system constraints and variables are treated as objects and are dened within
Alma-0
Search WWH ::




Custom Search