【发布时间】:2012-10-16 11:42:59
【问题描述】:
我是using a predicate,在 prolog 程序 shell 的连续提示中读取一些值,我希望用户在被要求输入时能够获得帮助消息。场景是:
- 征求意见
- 如果是
input = 'help',显示帮助信息并再次请求相同的输入 - 如果
input /= 'help',分配Value,成功离开
到目前为止我做了什么:
ask_input( Question, Value ) :-
write( Question ), % Please enter ... :
read( ReadValue ),
( ReadValue = 'help' ->
write( 'Help message...' ),
ask_input( Question, Value )
; Value = ReadValue
).
显然,上面的代码不起作用。它将在条件内的ask_input 上失败。
【问题讨论】:
标签: input prolog swi-prolog