没有为 maplist(all_distinct, list) 充分实例化

Not sufficiently instantiated for maplist(all_distinct, list)

我无法 运行 这段代码,对于允许 maplist/2 到 运行 all_distinct/1 的列表,我到底要说些什么?

Solution = [A, B, C, D, E, F, G, H, I], 
Solution ins 1..9, 
maplist(all_distinct, Solution).

我得到 ERROR: Arguments are not sufficiently instantiated。我知道我没有告诉它关于数字列表的足够信息,但我不知道我需要告诉它什么。我想要一个包含 1 到 9 的 9 个不同数字的列表。

这是我尝试执行时的跟踪:

   Call: (7) puzzle(_G548) ? creep
   Call: (8) _G548=[_G656, _G659, _G662, _G665, _G668, _G671, _G674, _G677|...] ? creep
   Exit: (8) [_G656, _G659, _G662, _G665, _G668, _G671, _G674, _G677|...]=[_G656, _G659, _G662, _G665, _G668, _G671, _G674, _G677|...] ? creep
   Call: (8) clpfd: ([_G656, _G659, _G662, _G665, _G668, _G671, _G674|...]ins 1..9) ? creep
   Call: (9) error:must_be(list, [_G656, _G659, _G662, _G665, _G668, _G671, _G674|...]) ? creep
   Exit: (9) error:must_be(list, [_G656, _G659, _G662, _G665, _G668, _G671, _G674|...]) ? creep
   Call: (9) clpfd:'__aux_maplist/2_fd_variable+0'([_G656, _G659, _G662, _G665, _G668, _G671, _G674|...]) ? creep
   Call: (10) clpfd:fd_variable(_G656) ? creep
   Call: (11) var(_G656) ? creep
   Exit: (11) var(_G656) ? creep
   Call: (11) true ? creep
   Exit: (11) true ? creep
   Exit: (10) clpfd:fd_variable(_G656) ? creep
   Call: (10) clpfd:'__aux_maplist/2_fd_variable+0'([_G659, _G662, _G665, _G668, _G671, _G674, _G677|...]) ? creep

看起来 ins/2 可能没有工作,然后仍然假冒 maplist/2?我不知道发生了什么。

你正在做的是你正在制作一个变量列表,Solutions,然后 Solutions ins 1..9 使 each 变量成为 1 到 1 之间的整数9.

all_distinct/1 需要一个列表,而不是整数。

因此,如果您想要一个包含 9 个 distinct 个整数的列表:

?- Solutions = [A,B,C,D,E,F,G,H,I],
   Solutions ins 1..9,
   all_distinct(Solutions).
L = [A, B, C, D, E, F, G, H, I],
A in 1..9,
all_distinct([A, B, C, D, E, F, G, H|...]),
B in 1..9,
C in 1..9,
D in 1..9,
E in 1..9,
F in 1..9,
G in 1..9,
H in 1..9,
I in 1..9.