I am studying DCG grammar and parse tree using the Ivan Bratko book: Programming fro Artificial Intelligence.
On the book I found the following example that show a DCG grammar that also generate a parse tree and a meaning/2 predicate that is used to mean the position after some moves.
This is the code:
move(move(Step)) --> step(Step).
move(move(Step, Move)) --> step(Step), move(Move).
step(step(up)) --> [up].
step(step(down)) --> [down].
meaning(move(Step, Move), Dist):- meaning(Step, D1),
meaning(Move, D2),
Dist is (D1 + D2).
meaning(step(Step), Dist):- meaning(Step, Dist).
meaning(step(up), 1).
meaning(step(down), -1).
On the book show the following query with the following output:
move(Tree, [up,up,down, up, up], []), meaning(Tree, Dist).
Tree = move(step(up), move(step(up), move(step(down), move(step(up), move(step(up)))))),
Dist = 3
The problem is that if I try to execute the previous query, I always obtain FALSE (I obtain false with whatever query...)
?- move(Tree, [up,up,down, up, up], []), meaning(Tree, Dist).
false.
Why? What is wrong? What ma I missing?