0

我正在尝试通过按下 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),
    !.

但我有这样的错误:http: //imgur.com/a/9N546 我该如何解决?我的第二个问题是:是否可以仅在对话框窗口中打印此结果?提前致谢。

4

1 回答 1

1

这是可以做的一个例子

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')).
于 2017-05-14T21:47:18.100 回答