I was trying to make an interface in Prolog using XPCE. I was using Dialog Editor and it generated my code in Prolog. When I click on SUM button nothing happens, i dont understand why but I think that problem is sum clause.
dialog(zbrajanje,
[ object :=
Zbrajanje,
parts :=
[ Zbrajanje :=
dialog('Zbrajanje'),
Unesi :=
button(unesi),
Odustani :=
button(odustani),
Text_item_1 :=
text_item(text_item1),
Text_item_2 :=
text_item(text_item2),
Rezultat :=
text_item('Rezultat')
],
modifications :=
[ Text_item_1 := [ length := 26
]
],
layout :=
[ area(Unesi,
area(52, 148, 80, 24)),
area(Odustani,
area(224, 146, 80, 24)),
area(Text_item_2,
area(66, 39, 260, 24)),
area(Text_item_1,
area(66, 63, 260, 24)),
area(Rezultat,
area(67, 90, 246, 24))
],
behaviour :=
[ SUM := [ message := message(@prolog,
sum,
Text_item_2?selection,
Text_item_1?selection,
Rezultat)
],
EXIT := [ message := message(Zbrajanje, return, @nil)
]
]
]).
sum(X,0,X).
sum(X,Y,S):-
S = X+Y.
inic(Var) :- make_dialog(D,zbrajanje ),
get(D, confirm_centered, R),
send(D,destroy),
Var = R.
Your definition of the
sum/3
predicate is not correct. The=/2
predicate/operator performs unification between terms. You want arithmetic evaluation, which uses theis/2
predicate/operator. Try instead: