PART II - The Ciao basic language

Author(s): The Ciao Development Team.

This part documents the Ciao basic language. It covers the basic language concepts, constructs, and some predefined predicates and declarations that, unless stated otherwise, are available by default every Ciao program as defined in the prelude package.

Most of these basic predicates are contained in the engine modules. The rest of the standard library predicates, including the packages that provide most of the ISO-Prolog builtins, are documented in subsequent parts.

Additionally, this prelude package can be omitted per module when some special packages are used (see noprelude, pure).

Syntax terminology and notational conventions

This manual assumes some familiarity with logic programming and the Prolog language. The reader is referred to standard textbooks on logic programming and Prolog (such as, e.g., [SS86,CM81,Apt97,Hog84]) for background. However, we would like to refresh herein some concepts for the sake of establishing terminology. Also, we will briefly introduce a few of the extensions that Ciao brings to the Prolog language.

Predicates and their components

Procedures are called predicates and predicate calls literals. They all have the classical syntax of procedures (and of logic predications and of mathematical functions). Predicates are identified in this manual by a keyword 'PREDICATE' at the right margin of the place where they are documented.

Program instructions are expressions made up of control constructs (Control constructs/predicates) and literals, and are 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 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

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

Predicate specs

Predicates are distinguished by their name and their arity. We will call name/arity a predicate spec. 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.

(Note that different predicates may have the same name and different arity. Conversely, of course, they may have the same arity and different name.)


When documenting a predicate, we will often describe its usage with a mode spec which has the form name(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 by in programs using the modedef/1 declarations of the Ciao assertion language (The Ciao assertion language for details). Modes are identified in this manual by a keyword 'MODE'.

Herein, we will use the set of modes defined in the Ciao isomodes library, which is essentially the same as 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. There may be properties of the states and of the computation. Properties of the states allow expressing characteristics of the program variables during computation, like in sorted(X) (X is a sorted list). Properties of the computation allow expressing characteristics of a whole computation, like 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 a keyword 'PROPERTY'.

Ciao types are regular types (Declaring regular types), which are a special form of properties themselves. They are identified in this manual by a keyword 'REGTYPE'.


A declaration provides information to one of the Ciao environment tools. Declarations are interspersed in the code of a program. Usually the target tool is either 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.), or the autodocumenter (which understands the previous declarations and also certain “comment” declarations).

A declaration has the form :- D. where D is syntactically the same as a literal. Declarations are identified in this manual by a 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 Extending the syntax). There are many such extensions in Ciao. The functions library, which provides fuctional syntax, is an example. The fact that in Ciao expansions are local to modules (as operators, see below) makes it possible to use a certain language extension in one module without affecting other modules.


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. However, some operators are standard and allowed 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.