Prolog:从父规则读取访问权限

时间:2012-09-27 21:32:08

标签: prolog

我想要一个特定的规则来读取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).

这可能吗?

1 个答案:

答案 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.