【发布时间】:2022-01-20 03:59:49
【问题描述】:
如何在内部术语上使用maplist?
假设 KB 为:
gate(not(o), i).
gate(not(i), o).
gate(and(o, i), o).
gate(and(i, o), o).
gate(and(B, B), B).
bits([i,o,o,i,i]).
以下操作无效:
?- bits(BITS), maplist(gate(not(X), Y), BITS, ANS)
如何映射列表以便:
[i,o,o,i,i] -> [not(i), not(o), not(o), not(i), not(i)] ->[o,i,i,o,o]
这可以在任何列表长度上完成:
:- bits([A,B,C,D,E]), gate(not(A), Anew), gate(not(B), Bnew), gate(not(C), Cnew), gate(not(D), Dnew), gate(not(E), Enew), ANS = [Anew, Bnew, Cnew, Dnew, Enew].
所以答案是:ANS = [o, i, i, o, o]
【问题讨论】:
标签: list prolog functor maplist