Download Sceptic Version 4 User Manual

Transcript
1 The Sceptic Language
Sceptic is a programming language which extends Prolog (see, for example, Clocksin & Mellish, 1981)
by the addition of a forward chaining control structure (the `conditional rewrite rule'). This control
structure allows procedural control aspects of a program to be distinguished from purely declarative
aspects, which may be expressed in a subset of standard Prolog.
The Sceptic execution model revolves around a changing database. Rewrite rules test this database and
conditionally modify the database or trigger further rewrite rules. A Sceptic program generally consists
of a specication of an initial state of the database and a set of rules which specify how the database
evolves over time, or how the database changes in response to particular events.
1.1 Basic concepts
Sceptic interfaces to its database via two basic kinds of entities:
Conditions: These are similar to Prolog predicates. They are purely logical objects which may query
the database but not alter it. Paralleling Prolog predicates, conditions may succeed, instantiating
variables contained therein, or fail.
Actions: These explicitly perform what are normally side eects within Prolog. Most importantly, they
allow output and database modication. There is no notion of success or failure for actions, and
they do not instantiate variables.
Conditions are either primitive or complex. The primitive conditions are just the Prolog primitives which
have no side-eects. Complex conditions may be dened via predicate denitions as in standard Prolog,
with the restriction that only conditions (primitive or complex) may be employed in the denition. In
particular, Prolog primitives with side-eects (such as those which modify the database) may not be
employed in the denition of complex conditions. This ensures that all conditions, primitive or complex,
have no side-eects.
Actions, like conditions, may also be primitive or complex. The primitive actions are those Prolog primitives which have side-eects: most notably, database modication primitives and output primitives.
Complex actions (which are sometimes referred to as `non-terminals') are dened via `triggered productions', or `conditional rewrite rules'. These provide declarative denitions of processes in terms of their
subprocesses and the conditions which govern their execution.
The two varieties of statement available in Sceptic allow a division between process control, which
is specied in terms of forward chaining rewrite rules, and the declarative specication of conditions
implicated in that control. That is, a programming style may be adopted within Sceptic whereby a
program consists of a set of conditional rewrite rules which specify the possible control processes, together
with a set of predicate denitions which specify the conditions which govern that control.
1.2 Syntax
Much of Sceptic's syntax is inherited from Prolog. In particular, all terms in Sceptic are Prolog terms and
the same conventions are used for distinguishing variables and ground terms. Thus, ground terms are
either atomic (consisting of either a string of alphanumeric characters beginning with a lowercase letter
or an arbitrary sequence of characters enclosed in single quotes), or complex (consisting of an atomic
term followed by an open bracket, a comma separated argument list, and a close bracket) and variables
are strings of alphanumeric characters beginning with an uppercase letter or an underscore. term, 'Time
14' and attribute(packet, square) are terms. Time14 and _Target are variables.
As mentioned above, complex conditions are dened via standard Prolog, viz :
Condition :- SubConditions.
1