2015-02-10 113 views
0

我无法运行此代码,关于允许maplist/2运行all_distinct/1的列表,我有什么要说的?未充分实例化maplist(all_distinct,列表)

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

我得到ERROR: Arguments are not sufficiently instantiated。我明白我对数字列表没有足够的了解,但我不知道我需要告诉它什么。我想通过9

9个不同的数字1的名单这里有一个跟踪,当我尝试执行:

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?我不知道发生了什么。

+1

事实上,一个'type_error(列表,X)'将有更多的帮助 – false 2015-02-10 14:32:05

+0

@false你或许应该报告为bug – 2015-02-10 14:36:09

+0

@Boris:2013年8月8日作为i3a#314提交。但它是一个非常多毛的情况,因为一个变量通常不会与类型错误相关联。是的,没有任何实例可以成为有效的术语,所以类型错误似乎很有意义,但它仍然处于边缘。 – false 2015-02-10 14:54:55

回答

4

你在做什么是你正在变量,Solutions一个列表,然后Solutions ins 1..9使得每个变量整数1到9之间

all_distinct/1期望一个列表,而不是一个整数。

所以,如果你想的9个不同整数的列表:

?- 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.