Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Prolog 如何在XPCE中按下按钮后打印功能结果_Prolog_Swi Prolog_Xpce - Fatal编程技术网

Prolog 如何在XPCE中按下按钮后打印功能结果

Prolog 如何在XPCE中按下按钮后打印功能结果,prolog,swi-prolog,xpce,Prolog,Swi Prolog,Xpce,我试图通过按下XPCE中的按钮来打印函数结果。这是我的密码: /* 11) Max square */ max_square(M, A) :- findall(P, country(A, P, _, _), L), write('Max square in thousands km^2: '), aggregate(max(E), member(E, L), M), write(M), forall(country(A, M,_, _),format(',

我试图通过按下XPCE中的按钮来打印函数结果。这是我的密码:

/* 11) Max square */
max_square(M, A) :-
    findall(P, country(A, P, _, _), L),
    write('Max square in thousands km^2: '),
    aggregate(max(E), member(E, L), M),
    write(M),
    forall(country(A, M,_, _),format(',~w~n', [A])).

:- use_module(library(pce)).

test:-
    new(D, dialog),
    new(W,  window('Test', size(100, 100))),
    send(D, append, new(button(B, max_square, message(@prolog, max_square, M, A)))),
    send(D, below, W),
    send(D, open),
    !.
但我有这样的错误:
我怎样才能修好它?我的第二个问题是:是否可以在对话框窗口中打印这个结果?提前感谢。

这是一个可以完成的示例

palindrome :-
    new(D, dialog('Palindrome')),
    new(Etiq, text_item('Is it a palindrome')),
    send(D, append, Etiq),
    new(Result, label),
    send(D, append, Result),
    send(D, append, button(test, message(@prolog, affiche, Etiq, Result))),
    send(D, append, button( cancel, message(D, destroy)) ),
    send(D, open).

affiche(Etiq, Result):-
    get(Etiq, selection, Text),
    atom_codes(Text, Str),
    (   reverse(Str, Str)
    ->   send(Result, selection, 'This is a palindrome')
    ;   send(Result, selection, 'This is not a palindrome')).

这不是一个错误,而是一个警告。然而,无论如何你都应该纠正它,因为它通常意味着你可能在某个地方有逻辑问题。单例变量是在逻辑中只出现一次的变量。除非你在其他地方引用它们,否则它们没有多大用处。