Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of slash after the predicate name in Prolog?

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?

like image 582
Animesh Pandey Avatar asked Oct 17 '12 13:10

Animesh Pandey


People also ask

What is Slash in Prolog?

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.

What do you mean by predicate in Prolog?

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.

How do you write an implication in Prolog?

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).

What are variables atoms and terms in Prolog?

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.


2 Answers

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.

like image 161
ely Avatar answered Oct 12 '22 02:10

ely


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.
like image 25
CapelliC Avatar answered Oct 12 '22 03:10

CapelliC