所示示例可以使用基本 I/O 例程 write/1、read/1 和 nl/0 来完成:
best_team(bills).
main :-
repeat,
write('Can you guest what the best team name is?'), nl,
read(X),
best_team(X),
write('You are right!'), nl, !.
| ?- main.
Can you guest what the best team name is?
giants.
Can you guest what the best team name is?
bills.
You are right!
yes
| ?-
这可以很容易地扩展为“你错了!”错误响应的消息。一种方法是:
main :-
repeat,
write('Can you guest what the best team name is?'), nl,
read(X),
( best_team(X)
-> write('You are right!'), nl, !
; write('You are wrong!'), nl, fail
).
这将导致:
| ?- main.
Can you guest what the best team name is?
giants.
You are wrong!
Can you guest what the best team name is?
bills.
You are right!
yes
| ?-
如果要输入带有标点符号、大写单词等的输入,则需要使用其他谓词。在这个话题上有一个recent question posted。