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