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
Asked
Active
Viewed 444 times
0
-
What have you tried so far? Show the code you've been working on. – lurker Apr 02 '18 at 11:05
-
@lurker I have tried to use repeat but it caused a lot of problems , so I have to find another way , keeping in mind that I want to keep a set of all the inputs. – Mahmood Yousef Apr 02 '18 at 17:20
1 Answers
0
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
).
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.

lurker
- 56,987
- 9
- 69
- 103