gpt4 book ai didi

Prolog:访问从父规则读取

转载 作者:行者123 更新时间:2023-12-02 08:25:21 25 4
gpt4 key购买 nike

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

这可能吗?

最佳答案

好吧,你已经有了解决方案:

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.

关于Prolog:访问从父规则读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12630326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com