Without creating a list, how can I query the integers between two values in Prolog?

StackOverflow https://stackoverflow.com/questions/275660

  •  07-07-2019
  •  | 
  •  

Question

For example, if I make a query like between(1,4,X)? I would expect something like X=2, X=3. Is this possible?

Was it helpful?

Solution

 between(A,B,X):-X is A+1,X<B.
 between(A,B,X):-A2 is A+1,A2<B-1,between(A2,B,X).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top