fork download
  1. :- set_prolog_flag(verbose,silent).
  2. :- prompt(_, '').
  3. :- use_module(library(readutil)).
  4.  
  5.  
  6. % monkey grasps banana
  7. act(state(middle, onbox, middle, hasnot),
  8. grasp,
  9. state(middle, onbox, middle, has) ).
  10.  
  11. % monkey climbs box
  12. act(state(P, onfloor, P, H),
  13. climb,
  14. state(P, onbox, P, H) ).
  15.  
  16. % monkey pushes box from P1 to P2
  17. act(state(P1, onfloor, P1, H),
  18. push(P1, P2),
  19. state(P2, onfloor, P2, H) ).
  20.  
  21. % monkey moves from P1 to P2
  22. act(state(P1, onfloor, B, H),
  23. walk(P1, P2),
  24. state(P2, onfloor, B, H) ).
  25.  
  26. % define (recursively) how the monkey can get the banana
  27. canget(state(_,_,_,has)).
  28. canget(State1) :- act(State1, _Action, State2), canget(State2).
  29.  
  30. % define the initial starting condition
  31. go :- canget( state(atdoor, onfloor, atwindow, hasnot) ).
  32.  
  33.  
  34. :- go, write("success!") ; write("fail!").
  35.  
  36.  
Success #stdin #stdout #stderr 0.04s 7040KB
stdin
Standard input is empty
stdout
success!
stderr
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit