visual-prolog

Can I keep track of value I'm getting in an other variable while working in a recursion?

爱⌒轻易说出口 提交于 2019-12-13 21:15:14
问题 predicates pathdistance(symbol,symbol,integer). solve(symbol,symbol,integer). clauses pathdistance(a,b,10). pathdistance(b,c,20). pathdistance(c,d,5). pathdistance(d,e,15). pathdistance(a,d,5). pathdistance(c,e,10). solve(X,Z,C):- pathdistance(X,Z,C). solve(X,Z,C):- pathdistance(X,Y,Cost), solve(Y,Z,C), Cost is Cost+C. goal solve(a,d,Cost). The answer I wanted for the Cost is the sum of all the C's (total distance) between a and d.The above code is not working, it is not allowing me to take a

Prolog - Little exercise on facts

萝らか妹 提交于 2019-12-12 03:14:48
问题 Ok. That's my problem. I need to implement a predicate that sums up all the prices of the products in the list. But, for now, I'm not getting any further with it. What am I doing wrong? Thanks in advance. domains state = reduced ; normal database producte (string, integer, state) predicates nondeterm calculate(integer) clauses % ---> producte( description , price , state ) producte("Enciam",2,normal). producte("Llet",1,reduced). producte("Formatge",5,normal). calculate(Import):- producte(_

Visual Prolog: Maximum number of anyflow

﹥>﹥吖頭↗ 提交于 2019-12-11 13:49:32
问题 I get an error message Maximum number of anyflow variants (1000) exceeded when trying to execute this code: findNegative([], []). findNegative([Q|V], Y) :- Q > 0, !, findNegative(V, Y). findNegative([H1|T1], S) :- findNegative(T1, [H1|S]). Same when trying to execute code from this answer: https://stackoverflow.com/a/6671142/4829408 回答1: Consider the following code: find_negatives([], [] ). find_negatives([E|Es], Xs ) :- E >= 0, find_negatives(Es, Xs). find_negatives([E|Es], [E|Xs]) :- E < 0,

“Not equal” sign in Visual Prolog?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 07:43:25
问题 I can't find any documentation on "not equal" sign in Visual Prolog. Please provide the right solution of this problem: class predicates sister : (string Person, string Sister) nondeterm(o,o). clauses sister(Person, Sister) :- Person [not-equal-sign] Sister, parent(Person, Parent), parent(Sister, Parent), woman(Sister). 回答1: I don't know what do you mean by "not equal" (does not unify?), but you could try these: X \= Y not(X = Y) \+ (X = Y) 回答2: Documentation for the second variant pointed

“Not equal” sign in Visual Prolog?

自作多情 提交于 2019-12-03 10:32:00
I can't find any documentation on "not equal" sign in Visual Prolog. Please provide the right solution of this problem: class predicates sister : (string Person, string Sister) nondeterm(o,o). clauses sister(Person, Sister) :- Person [not-equal-sign] Sister, parent(Person, Parent), parent(Sister, Parent), woman(Sister). I don't know what do you mean by "not equal" (does not unify?), but you could try these: X \= Y not(X = Y) \+ (X = Y) Documentation for the second variant pointed out by Kaarel can be found in this Visual Prolog reference page. However the problem with your code goes a little