我想要一个特定的规则来读取SWI-Prolog中的用户输入数据,例如:
process( ... ) :-
% do_stuff
read_values( ... ),
% do_more_stuff with X and Y here.
read_values( ... ) :-
write('Please enter X: '),
read(X),
write('Please enter Y: '),
read(Y).
这可能吗?
答案 0 :(得分:3)
嗯,你已经有了解决方案:
process :-
% do_stuff
read_values(A, B),
% do_more_stuff with X and Y here
atom_concat(A, B, C),
writeln(C).
read_values(X, Y) :-
write('Please enter X: '),
read(X),
write('Please enter Y: '),
read(Y).
示例运行:
?- process.
Please enter X: a.
Please enter Y: b.
ab
true.