Debugging Prolog-使用maplist应用参数
我想了解我的错误是什么,这段代码用于带有列表的maplist的自定义谓词:Debugging Prolog-使用maplist应用参数,debugging,prolog,maplist,Debugging,Prolog,Maplist,我想了解我的错误是什么,这段代码用于带有列表的maplist的自定义谓词: generateProjection(TableOrTables/Selectors, Row, Result) :- writeln(kiki), writeln(TableOrTables), writeln(Selectors), writeln(Row), Result = 1/2. compute_projection(Rows, TableOrTables, Sel
generateProjection(TableOrTables/Selectors, Row, Result) :-
writeln(kiki),
writeln(TableOrTables),
writeln(Selectors),
writeln(Row),
Result = 1/2.
compute_projection(Rows, TableOrTables, Selectors, Result) :-
writeln(hello),
writeln(Rows),
writeln(Selectors),
maplist(
generateProjection(TableOrTables/Selectors),
Rows,
Result
).
此查询可用于:
generateProjection(foo/[foo/bar, foo/baz], [1, 2], Z).
鉴于这一点失败:
compute_projection([[1, 2], [3, 4]], foo, [foo/bar, foo/baz], _4552/_4554).
感谢您的帮助让我们看看您的第二个问题: ?- compute_projection([[1,2],[3,4]], foo, [foo/bar,foo/baz], _A/_B). 因此,
Result
是一个列表,但查询需要一个形式为\uu/
的术语
这就是查询无法成功的原因。我想在compute_projection中做的是生成一个由generateProjection生成的u/u列表(这样我就可以在上面使用findall)。我怎样才能修好它?使用另一个变量?@jy95。你已经在这么做了。因此,
Result
的形式为[]
或[\u/\ u]
或[\u/\ uu、\u/\ u]
等。。。用变量替换\u A/\u B
后再次运行查询…感谢您的回答:)
compute_projection(Rows, TableOrTables, Selectors, Result) :-
maplist(generateProjection(TableOrTables/Selectors),
Rows,
Result).