如何从XPCE的prolog谓词中读取

我有以下简单的序言谓词:
tst(In, Out) :- Out = In.
这个想法很清楚,只需按照“In”中的“Out”返回相同的内容即可。好的,现在我想在XPCE程序中包含这个prolog谓词。我创建了一个窗口,并添加了一个应该调用此prolog谓词的按钮,然后显示“Out”中返回的值。我认为实现这个任务就像这样简单
send(Dialog, append(button(execute_command, and(
  message(@prolog, tst, InputText?selection, prolog(Output)),
  message(@prolog, write, prolog(Output)),
  message(@prolog, nl))))),
但不幸的是,这并不像我想要的那样完全正常。相反,它现在打印出“Out”的内部引用。例如:
?- _L204
任何想法在这里我的错误是什么?     
已邀请:
从PCE中的Prolog设置值很容易,使用send / 3或send / 4。因此,解决此问题的一种方法是让Prolog谓词调用一个在PCE对象上设置值的方法。 对象可以包含其他对象,并在范围内包含类和实例变量。所有Prolog代码需要的是对对象的引用:通过使用对象引用调用谓词,谓词可以调用适当的方法来传递值。 下面是一些基于对话框类创建对象的代码。按下对象中的按钮时,将调用谓词(类似于此问题中的一个),该谓词将根据传入的值创建值,然后在对话框的实例变量中设置该值。它还会将值放在text_ item控件中。 这个程序源是textfield.pl,可以运行
swipl -s textfield.pl -g run
默认文字: 用户输入 程序通过从按钮调用的谓词发送到GUI的消息更新文本: 演示类:
:- use_module(library(pce)).

:- pce_begin_class(demo, dialog).
/* Instance variables*
         name,   type,  access, description */
variable(result, name*, get,    "Result from Prolog Callback").

initialise(Demo) :->
    "Create something that get/4 and send/3 can work with."::
    send(Demo, send_super, initialise, 'Demo'),
    send(Demo, append, new(InputText, text_item(input, 'Demo Text'))),
    send(Demo, append,
         button(execute_command,
            and(message(@prolog,doIt, Demo,InputText?selection),
            message(@prolog,printIt,Demo)))).
:- pce_end_class.
按钮调用的代码:
%%% Create a new value based on the input string
%%% Write the new value back to the 'input' member of the
%%% 'demo' object.  Also put the value int the 'result' slot.
doIt(Demo,Word) :-
    concat_atom(['*** ' , Word, ' *** '] ,WordGotDid),
    format("doIt: Setting result: ~w...~n", [WordGotDid]),
    get(Demo,member,input,InputText),
    send(InputText,selection,WordGotDid),
    send(Demo,slot,result,WordGotDid).

%%% Read and display the 'result' slot.
printIt(Demo) :-
    get(Demo,slot,result,Result),
    write('nResult: "'),
    write(Result),
    write('"n').
主程序:
%%% Create an object that has fields that can be mutated.
run :- new(Demo,demo),
    send(Demo,open).
在看了演示并编写了这个演示之后,一旦我完成了对XPCE的学习,这是我的意见,这可能会改变:尽管有些可能通过来自XPCE的消息在Prolog中编程,查看演示代码,但这不是它的方式。编程是用Prolog或其他语言完成的,Prolog是胶水,而XPCE主要是被动GUI,有点像HTML表单。该程序创建XPCE对象,更改其状态并从中读取值。除了一些与GUI相关的小消息之外,XPCE通常不会写入程序;但即使这通常也是在XPCE对象的方法中完成的。     

要回复问题请先登录注册