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?
you can ‘invoke’ alternative bindings on
Ythis way:Note the parenthesis are required to keep the correct execution control flow. The
;/2 it’s the generaloroperator. For your restricted use you could as well choice the more idiomaticthat on backtracking binds Y to each member of the list.
edit I understood with a delay your last requirement. If you want that Y match all 3 values the or is inappropriate, use instead
or the more compact
findall/3 build the list in the very same order that registered/2 succeeds. Then I use sort to ensure the matching.
setof/3 also sorts the result list