I fail to see why 5(X,Y) is syntactically not correct, while +(north,west) is correct.
A single digit is not an atom, but a number.
On page 33 section 2.1.1 Atoms and numbers it reads:
Atoms can be constructed in three ways:
1. Strings of letters, digits and the underscore character,
starting with a lower-case letter.
2. Strings of special characters such as + - * / < > = : . & _ ~
3. Strings of characters enclosed in single quotes.
The character 5
- fails rule 1 because the string does not start with an underscore
character or a lower-case letter
- fails rule 2 because it is not one
of the special characters
- fails rule 3 because it is not enclosed
in single quotes
The character +
succeeds because by rule 2 it is a special character.
One way to explore this further is by using SWI-Prolog functor/3
?- functor(+(north,west),Name,Arity).
Name = (+),
Arity = 2.
?- functor(5(X,Y).
ERROR: Syntax error: Operator expected
ERROR: functor(
ERROR: ** here **
ERROR: 5(X,Y) .
what the exact difference is between a relation and a structure
On page 4 Section 1.1 Defining relations by facts
In general, a relation is defined as the set of all its instances. For example parent(tom,bob) is a particular instance of the parent relation. With other instances being:
parent(pam,bob)
parent(tom,liz)
parent(bob,ann)
parent(bob,pat)
parent(pat,jim)
On page 35 Section 2.1.3 Structures
Structured objects (or simply structures) are objects that have several components, e.g.
date(1, may, 2001)
point(1,1)
seg(P1,P2)
seg(point(1,1),point(2,3))
(a + b) * (c - 5) % uses infix operator
*(+(a,b),-(c,5)) % uses prefix operator
Looking at your question makes me think you are looking for a property common to both relation and structure that can be used to distinguish one from the other. I don't know of one; when I think about using Prolog I don't think should I use a relation or a structure
, I think of how is the data structured
which can be as simple as a number or more complex as a structure or a structure of structures, and then what are the predicates (rules) that are needed to reach a goal
given the data. In looking at the definitions given the best I can say is that a specific relation can be composed of many structures that have the same functor, but that is not an idea that will last in my mind past this period.
atom(5)
fails. So technically a number is not an atom. I don't have that particular book, so it would be interesting to know the context of their claim that an atom can also be a digit. – lurker