1.2 Prolog Syntax

Now that we've got some idea of what Prolog does, it's time to go back to the beginning and work through the details more carefully. Let's start by asking a very basic question: we've seen all kinds of expressions (for example jody, playsAirGuitar(mia), and X) in our Prolog programs, but these have just been examples. Exactly what are facts, rules, and queries built out of?

The answer is terms, and there are four kinds of terms in Prolog: atoms, numbers, variables, and complex terms (or structures). Atoms and numbers are lumped together under the heading constants, and constants and variables together make up the simple terms of Prolog.

Let's take a closer look. To make things crystal clear, let's first get clear about the basic characters (or symbols) at our disposal. The upper-case letters are A, B, ..., Z; the lower-case letters are a, b, ..., z; the digits are 1, 2, ..., 9; and the special characters are +, -, *, /, <, >, =, :, ., &, ~, and _. The _ character is called underscore. The blank space is also a character, but a rather unusual one, being invisible. A string is an unbroken sequence of characters.

Patrick Blackburn, Johan Bos and Kristina Striegnitz
Version 1.2.5 (20030212)