I'm using a predicate to read some values in consecutive prompts in a prolog program shell, and I want the user to be able to get a help message when asked for input. The scenario would be:
- Ask for input
- If
input = 'help'
, display help message and ask for the same input again - If
input /= 'help'
, assignValue
and leave successfully
What I've done so far:
ask_input( Question, Value ) :-
write( Question ), % Please enter ... :
read( ReadValue ),
( ReadValue = 'help' ->
write( 'Help message...' ),
ask_input( Question, Value )
; Value = ReadValue
).
Obviously, the code above does not work. It will fail on the ask_input
inside the condition.