读取输入直到退出语句序言 [英] Read Input till quit statement prolog
问题描述
所以我正在编写一个聊天机器人,我需要不断地从用户那里获取输入,只要他们不输入退出".但如果他们这样做了,我必须对用户提出的问题进行一定的回顾和然后返回 true ,我在使用谓词时遇到问题,该谓词将继续读取输入直到输入退出,有人可以帮助我吗?谢谢
So I'm coding a chat Bot and I need to keep taking input from the user as long as they don't type 'quit.', but if they do I must do a certain recap of what the user asked and then return true , I'm having trouble with the predicate that will keep reading the input till quit is typed , Can anyone help me? Thanks
推荐答案
这个问题措辞比较笼统,所以这里描述了如何使它在 Prolog 半伪代码中工作:
The question is worded rather generally, so here's a description of how to make it work in Prolog semi-pseudo-code:
user_input :-
repeat,
read_a_line(Line),
( Line = quit % You might have another way to check this depending...
-> write('Finished'), nl,
!, true
; do_something_with(Line),
fail
).
repeat-fail
循环的工作方式是让您不想继续执行循环.然后为了退出循环,您希望通过剪切成功.
The way the repeat-fail
loop works is that you want to fail to continue to do your loop. Then for exiting the loop, you want to succeed with a cut.
这篇关于读取输入直到退出语句序言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!