Prolog - apply arguments with maplist

437 Views Asked by At

I would like to understand what could be my error with this piece of code for custom predicate for maplist with a list of list :

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

This query works :

generateProjection(foo/[foo/bar, foo/baz], [1, 2], Z).

whereas this one fails :

compute_projection([[1, 2], [3, 4]], foo, [foo/bar, foo/baz], _4552/_4554).

Thanks for your help

1

There are 1 best solutions below

3
repeat On BEST ANSWER

Let's look at your second query:

?- compute_projection([[1,2],[3,4]], foo, [foo/bar,foo/baz], _A/_B).

maplist/3 relates two lists. Now let's look at the predicate definition again:

compute_projection(Rows, TableOrTables, Selectors, Result) :- 
    maplist(generateProjection(TableOrTables/Selectors),
            Rows,
            Result).

So Result is a list but the query demands a term of the form _/_.

This is why your query cannot succeed.