1

我试图使用 XPCE 在 Prolog 中创建一个界面。我正在使用对话框编辑器,它在 Prolog 中生成了我的代码。当我点击 SUM 按钮时没有任何反应,我不明白为什么,但我认为问题是 sum 子句。

对话编辑器

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.
4

1 回答 1

0

Your definition of the sum/3 predicate is not correct. The =/2 predicate/operator performs unification between terms. You want arithmetic evaluation, which uses the is/2 predicate/operator. Try instead:

..., S is X + Y.
于 2018-12-18T20:29:49.433 回答