1

I have this prolog code for solving monkey and banana problem but my compiler give an error

This is my code:


move(state(middle, onbox, middle, hasnot), grasp,
     state(middle, onbox, middle, has)).
move(state(Pos, onfloor, Pos, Has), climb,
     state(Pos, onbox, Pos, Has)).
move(state(Pos1, onfloor, Pos1, Has), push(Pos1, Pos2),
     state(Pos2, onfloor, Pos2, Has)).
move(state(Pos1, onfloor, Box, Has), walk(Pos1, Pos2),
     state(Pos2, onfloor, Box, Has)).

canget(state(_,_,_,has)).
canget(State1) :- move(State1, Move, State2), canget(State2).

Error: Move is Singleton Variable.
What is my wrong?

false
  • 10,264
  • 13
  • 101
  • 209
user3139746
  • 29
  • 1
  • 1
  • 4
  • "Singleton" means that you used a named variable only once in the lexical scope of a predicate clause. So, this variable is "ignored", and not used in any way in this clause, hence the warning. –  Dec 28 '14 at 07:55

1 Answers1

1
canget(S0) :-
   S = state(_,_,_,has),
   closure0(\X^Y^move(X,_,Y),S0,S).

Using closure0/3 and lambda

Community
  • 1
  • 1
false
  • 10,264
  • 13
  • 101
  • 209