I've read the SO questions what does slash(/) do in prolog? and What is the meaning of predicate “simple/1” in Prolog (SWI-Prolog), but these links don't seem to help me.
I was going though some beginner tutorials on Prolog.
Phrases like Solve/4
or Go/1
confused me. What does that slash and number mean?
As EMS and Chac explained this number denotes number of arguments. The reason why you will find this number in documentation is because predicates with same name and different arity (number of arguments) are different predicates.
A Prolog program consists of predicate definitions. A predicate denotes a property or relationship between objects. Definitions consist of clauses. A clause has a head and a body (Rule) or just a head (Fact). A head consists of a predicate name and arguments.
implication: in Prolog, these are very special. They are written backwards (conclusion first), and the conclusion must be an atomic formula. This backwards implication is written as ':-', and is called a rule. sibling(X, Y) :- parent(P, X), parent(P, Y).
Unification with typical Prolog terminology: Atoms, numbers, variables and compounds are terms. Atom = string that starts with a lower case letter. Number = a number. Variable = string that starts with a capital letter.
It is the number of arguments that the function expects in its signature. Be careful of infix operators, which can accept multiple arguments even if the way they are called is by placing them in between the arguments. That is, you can think of something like ordinary addition, +
, as a binary operator. So A+B
is really the same as +(A,B)
, which means you would define +
with +/2
.
I cite from page 8 of 'Prolog: The Standard: Reference Manual' (the 2^ entry when I googled 'prolog predicate indicator').
Predicate indicator ... It's a ground term of the form Name/Arity
The ISO builtin functor/3 accesses such data
?- functor(append(a,b,c),Name,Arity).
Name = append,
Arity = 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With