3

我想要一个在 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).

那可能吗?

4

1 回答 1

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.
于 2012-09-27T21:40:03.433 回答