[top] [up] [next]
Terms
The Prolog system recognizes the type of a term object by its syntax. A
variable always starts with an uppercase character and all other data types start with a
lowercase character. Below there is a picture showing the hierarchy of types in Prolog:
Atoms
Atoms are strings that consist of:
- Alphanumeric characters including the underscore character ( _ ) and that start
with a lowercase character (A..Z, a..z, _).
- Atoms enclosed in single or double quotes, for instance 'Papa bear' or "Papa
bear". By using quotes an atom can start with a capital and can contain whitespace
characters. Inserting a single double quote in a string that starts with a double quote is
done by placing two double quotes inside the string, for instance, "This string
""contains"" 2 extra double quotes". The two double quotes inside
the string are interpreted by the compiler as a single double quote. This is the same for
inserting a single quote inside a string that is enclosed by single quotes.
There is however a difference in using the single quote character and the double quote
character, single quotes are removed from the atom and double quotes not.
For example; the goal 'a' = a. succeeds because the single quotes are removed from the
atom 'a'. If the goal is "a"=a. then the result will be no because the double
quotes are not removed. There is also the Prolog double_quotes,
this Prolog flag determines how the compiler processes atoms enclosed by double quotes.
- An atom may also consist of the following special characters # $ % & * + - . / :
< = > @ \ ^ ` ~
Numbers
These are integer numbers like, 33, -33, 0, 23534 and floating point numbers like,
23.3e+34, -0.3532e-03. For the maximum and minimum values see the page 'Differences and limitations'.
Variables
Variables start with an uppercase character and then consist of
alphanumeric characters or the underscore character. Below there are some examples of
variables:
Var
X
Hello_this_is_a_variable
A variable that just consists of a single underscore characters is called an anonymous
variable.
Structures
Structures are data objects that consist of one or more other components, these can in
turn also be structures. These components are bounded by a functor. A
functor is an atom that binds the components. Below there are several examples of
structures:
mother(clair, jil).
point(12, 2).
functor_1( g(h, i), other_compound_term(A, b) ).
The arity of a structure is the number of components, the arity of point(12, 2) is 2
and the arity of triangle( 12, 2, 15) is 3.
[top] [up] [next]
info@trinc-prolog.com