Basic concepts and conventions

Author(s): The Ciao Development Team.

Syntax terminology and notational conventions

Ciao is a language that has its roots in (and includes) the Prolog language. Thus, this manual assumes some familiarity with logic programming and Prolog. The reader is referred to standard textbooks on these topics (such as, e.g., [SS86,CM81,Apt97,Hog84]) for background. However, we recall herein some concepts for the sake of establishing terminology. Also, we will briefly introduce some of the extensions that Ciao brings to the Prolog language that are instrumental for understanding this part of the manual.

Predicates and their components

In logic programming procedures are also called predicates and procedure call sites are also called literals. Predicates are identified in this manual by the keyword 'PREDICATE' in the place where they are documented.

Program instructions are expressions made up of control constructs (Control constructs/predicates) and procedure calls (literals). These expressions are also called goals. Literals are also (atomic) goals.

A predicate definition is a sequence of clauses. A clause has the form ``H :- B.'' (ending in '.'), where H is syntactically the same as a literal and is called the clause head, and B is a comma separated list of literals (a conjunction) goal and is called the clause body. A clause with no body is written ``H.'' and is called a fact. Clauses with body are also called rules. A program is a sequence of predicate definitions.

Characters and character strings vs. atoms

We adopt the following convention for representing character strings in the text of this manual: when a string is being used as an atom it is written thus: user or 'user'; in all other circumstances double quotes are used (as in "hello").

Predicate specs

Predicates are distinguished by their name and their arity (number of arguments). We will call name/arity a predicate spec. Note that there can be predicates that have the same name and different arity. These are different predicates (conversely, they may of course have the same arity and different name). The notation name/arity is therefore used when it is necessary to refer to a predicate unambiguously. For example, concatenate/3 specifies the predicate which is named ``concatenate'' and which takes 3 arguments.

Modes

When documenting a predicate, we will often describe how it is used with a mode spec which has the form predicate(Arg1, ..., ArgN) where each Arg may be preceded by a mode. A mode is a functor which is wrapped around an argument (or prepended if defined as an operator). Such a mode allows documenting in a compact way the instantiation state on call and exit of the argument to which it is applied. The set of modes which can be used in Ciao is not fixed. Instead, arbitrary modes can be defined in programs by using the modedef/1 declarations of the Ciao assertion language (see The Ciao assertion language for details). Modes are identified in this manual by the keyword 'MODE'.

Herein, we will use the set of modes defined in the Ciao isomodes library, which is essentially a precise definition of those used in the ISO-Prolog standard (ISO-Prolog modes).

Properties and types

Although Ciao is not a 'typed language,' it allows writing (and using) types, as well as more general properties. These may be properties of states and properties of computations. Properties of state allow expressing characteristics of the program variables at particular points in the computation, like in sorted(X) (X is a sorted list). Properties of the computation allow expressing characteristics of a whole computation for a predicate, as in is_det(p(X,Y)) (such calls yield only one solution). Properties are just a special form of predicates (Declaring regular types) and are identified in this manual by the keyword 'PROPERTY'.

In Ciao types are a particular case of property. A frequently used library of types is regular types (Declaring regular types). Properties of this kind are identified in this manual by the keyword 'REGTYPE'.

Declarations

A declaration provides information to one of the Ciao environment tools. Declarations are interspersed in the code of a program. The target tool can be the compiler (telling it that a predicate is dynamic, or a meta-predicate, etc.), the preprocessor (which understands declarations of properties and types, assertions, etc.), the autodocumenter (which understands the previous declarations and also certain ``comment'' declarations), or the debugger, among other tools.

A declaration has the form :- D. where D is syntactically the same as a literal. Declarations are identified in this manual by the keyword 'DECLARATION'.

In Ciao users can define (and document) new declarations. New declarations are typically useful when defining extensions to the language (which in Ciao are called packages). Such extensions are often implemented as expansions (see Packages and language extension). There are many such extensions in Ciao. The fsyntax library, which provides fuctional syntax, is an example. The fact that expansions in Ciao are local to modules (as operators, see below) makes it possible to use a certain language extension in a module without affecting other modules.

Operators

An operator is a functor (or predicate name) which has been declared as such, thus allowing its use in a prefix, infix, or suffix fashion, instead of the standard procedure-like fashion. E.g., declaring + as an infix operator allows writing X+Y instead of '+'(X,Y) (which may still, of course, be written).

Operators in Ciao are local to the module/file where they are declared. At the same time, some operators are standard and are declared by default in every program (see Defining operators). This manual documents the operator declarations in each (library) module where they are included. As with expansions, the fact that in Ciao operators are local to modules makes it possible to use a certain language extension in one module without affecting other modules.