如何在 XPCE 中读取 prolog 谓词
我有以下简单的序言谓词:
tst(In, Out) :- Out = In.
这个想法很明确,只需在“Out”中返回与“In”中收到的相同内容即可。好的,现在我想在 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
有什么想法我的错误是什么吗?
I have the following simple prolog predicate:
tst(In, Out) :- Out = In.
The idea is clear, simply return the same in "Out" as was received in "In". Ok, now I want to include this prolog predicate in a XPCE program. I have created a window and added a button that should call this prolog predicate, then display the value returned in "Out". I thought achieving this task would be as simple as
send(Dialog, append(button(execute_command, and(
message(@prolog, tst, InputText?selection, prolog(Output)),
message(@prolog, write, prolog(Output)),
message(@prolog, nl))))),
but unfortunately, that does not work exactly as I want it to. Instead it now prints out the internal reference of "Out". For example:
?- _L204
Any ideas what is my mistake here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 Prolog 在 PCE 中设置值很容易,使用 send/3 或 send/4。因此解决这个问题的一种方法是让 Prolog 谓词调用一个在 PCE 对象上设置值的方法。
对象可以包含其他对象,并且在范围内具有类和实例变量。 Prolog 代码所需要的只是对对象的引用:通过使用对象引用调用谓词,谓词可以调用适当的方法来传递值。
下面是一些基于 dialog 类创建对象的代码。按下对象中的按钮时,将调用一个谓词(类似于本问题中的谓词),该谓词将根据传入的值创建一个值,然后在实例变量中设置该值对话框。它还会将值放入 text_ item 控件中。
该程序源是textfield.pl,可以使用默认文本运行
:
用户输入
程序通过从按钮调用的谓词发送到 GUI 的消息来更新文本:
演示类:
按钮调用的代码:
主程序:
在查看演示并编码后,这是我的观点,一旦我完成 XPCE 的学习,它可能会改变:尽管如此,它有点可以通过来自 XPCE 的消息在 Prolog 中进行编程,查看演示代码,这不是它的完成方式。编程是用 Prolog 或其他语言完成的,并以 Prolog 作为粘合剂,而 XPCE 主要是一个被动的 GUI,有点像 HTML 表单。该程序创建 XPCE 对象,更改其状态并从中读取值。除了一些与 GUI 相关的小型消息传递之外,XPCE 通常不会写入程序;但即便如此,通常也是在 XPCE 对象的方法中完成的。
From Prolog setting values in PCE is easy,using send/3, or send/4. So one way around this is to have the Prolog predicate invoke a method that sets a value on a PCE object.
Objects can contain other objects, and have class and instance variables in scope. All the Prolog code needs is a reference to the object: By calling the predicate with an object reference, the predicate can invoke an appropriate method to communicate a value.
Here is some code that creates an object based on the dialog class. A button in the object, when pressed, will call a predicate (similar to the one in this question) that will create a value based on the one passed-in, then set that value in an instance variable of the dialog. It will also put the value in the text_ item control.
This program source is textfield.pl and can be run with
Default Text:
User Input
Text updated by the program via messages sent to the GUI from a predicate invoked by the pushbutton:
The demo class:
Code called by the pushbutton:
Main program:
After looking at the demos and coding this one, this is my opinion which could change, once I finish studying XPCE: Even though, it is somewhat possible to program in Prolog via messages from XPCE, looking at the demo code, this isn't the way it's done. The programming is done in Prolog or some other language and with Prolog as the glue, while XPCE is mostly a passive GUI, sort of like HTML forms. The program creates XPCE objects, changes their state and reads values from them. XPCE doesn't normally write to the program other than some small GUI-related messaging; but even that is usually done in the methods of XPCE objects.