Prolog "or" operator, query

Eogcloud picture Eogcloud · Nov 22, 2012 · Viewed 105.8k times · Source

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?

Answer

Robert Oschler picture Robert Oschler · Nov 23, 2012

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