gpt4 book ai didi

prolog - 我可以在 call/2 中添加参数列表吗?

转载 作者:行者123 更新时间:2023-12-05 04:12:31 24 4
gpt4 key购买 nike

call(Goal,Arg)允许将参数 Arg 附加到 Goal 的参数并调用结果目标,例如

call(succ(1), R).

相同
succ(1, R).

但是,我不想追加到参数列表,而是在前面添加,例如

callpre(succ(1), R).

应该导致

succ(R, 1).

如何将参数添加到 Goal 的参数列表中并调用生成的目标?

最佳答案

对于任意数量的参数,您可以将其定义为

callpre(MGoal, Arg) :-
strip_module(MGoal, M, Goal),
Goal =.. [F | Args],
NewGoal =.. [F, Arg|Args],
M:NewGoal.

你还需要一个 meta_predicate/1 声明:

:- meta_predicate callpre(1, *). 

关于prolog - 我可以在 call/2 中添加参数列表吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40173981/

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