I'm using the in/1
predicate to try and constrain an integer to take values from a certain set:
?- use_module(library(clpfd)).
gen_in_set(X) :-
X in [0, 1, 3, 5, 7].
I didn't expect this to work, since [...]
is list notation. I could of course use:
X #= 0 #\/ X #= 1 #\/ X #= 3 #\/ X #= 5 #\/ X #= 7.
but this is very verbose. The following also works:
X in 0 \/ 1 \/ 3 \/ 5 \/ 7.
and is a bit shorter, but still quite ugly.
The documentation states:
Var is an element of Domain. Domain is one of:
Integer Singleton set consisting only of Integer.
I've tried searching for what a singleton set is (Prolog newbie here), but I couldn't find anything online. Is there a cleaner way of expressing my constraint?