views:

106

answers:

1

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

+3  A: 
 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).
Martin v. Löwis
Thank you! I'm still at my beginning states of learning Prolog and I was stuck with this.
wallyqs
It took me ages to figure out that you need to use the 'is' keyword to do "assignment".
Matthew Schinckel
"is" actually is not "assignment". Instead, it performs a numerical computation on the RHS, and then a unification with the LHS.
Martin v. Löwis