Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog "or" operator, query

I'm working on some prolog that I'm new to.

I'm looking for an "or" operator

registered(X, Y), Y=ct101, Y=ct102, Y=ct103. 

Here's my query. What I want to write is code that will:

"return X, given that Y is equal to value Z OR value Q OR value P"

I'm asking it to return X if Y is equal to all 3 though. What's the or operator here? Is there one?

like image 475
Eogcloud Avatar asked Nov 22 '12 05:11

Eogcloud


People also ask

How do you do or operator in Prolog?

Performing an "or" in Prolog can also be done with the "disjunct" operator or semi-colon: registered(X, Y) :- X = ct101; X = ct102; X = ct103.

What is the symbol used for or operation in Prolog?

Alphabet of Prolog The alphabet of PROLOG consists of: C — a set of constant symbols (or constants, for short), V — a set of variable symbols (or variables, for short), F — a set of function (term) symbols, P — a set of relation (predicate) symbols.

How do you query in Prolog?

In making a query you are asking Prolog whether it can prove that your query is true. If so, it answers "yes" and displays any variable bindings that it made in coming up with the answer. If it fails to prove the query true, it answers "No". Whenever you run the Prolog interpreter, it will prompt you with ?-.

What is == in Prolog?

The = "operator" in Prolog is actually a predicate (with infix notation) =/2 that succeeds when the two terms are unified. Thus X = 2 or 2 = X amount to the same thing, a goal to unify X with 2. The == "operator" differs in that it succeeds only if the two terms are already identical without further unification.


1 Answers

Just another viewpoint. Performing an "or" in Prolog can also be done with the "disjunct" operator or semi-colon:

registered(X, Y) :-     X = ct101; X = ct102; X = ct103. 

For a fuller explanation:

Predicate control in Prolog

like image 112
Robert Oschler Avatar answered Sep 20 '22 12:09

Robert Oschler