For example, if I make a query like 'between(1,4,X)?' I would expect something like X=2,X=3. Is this possible?
views:
106answers:
1
+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
2008-11-09 07:00:02
Thank you! I'm still at my beginning states of learning Prolog and I was stuck with this.
wallyqs
2008-11-09 23:12:00
It took me ages to figure out that you need to use the 'is' keyword to do "assignment".
Matthew Schinckel
2008-11-27 03:16:47
"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
2008-11-27 06:51:35