How to print function result after pressing a button in XPCE

323 Views Asked by At

I am trying to print a function result via pressing a button in XPCE. Here is my code:

/* 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),
    !.

But I have such error: https://i.stack.imgur.com/8C1sK.jpg How could I fix it? And my second queston is: is it possible to print this result just in dialog window? Thanks in advance.

1

There are 1 best solutions below

0
On BEST ANSWER

This is an example of what can be done

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')).