
RULES

;;; Frame axioms

(frame-table
 if
 then
 (clear table (move ?obj ?src ?dst ?s)))

(frame-clear
 if
 ($test (clear ?x ?s))
 ($eval (not (equal? (quote ?x) (quote ?dst))))
 then
 (clear ?x (move ?obj ?src ?dst ?s)))

(frame-on
 if
 ($test (on ?x ?y ?s))
 ($eval (not (equal? (quote ?x) (quote ?obj))))
 then
 (on ?x ?y (move ?obj ?src ?dst ?s)))

;;; Actions

(puton
 if
 (clear ?obj ?s)
 (clear ?dst ?s)
 (on ?obj ?src ?s)
 ($eval (not (equal? (quote ?obj) (quote ?dst))))
 ($eval (not (equal? (quote ?src) (quote ?dst))))
 then
 (on ?obj ?dst (move ?obj ?src ?dst ?s)))

(clear0
 if
 ($not ($test (on ?y ?x ?s)))
 then
 (clear ?x ?s))

(clear1
 if
 (on ?obj ?src ?s)
 (clear ?obj ?s)
 (clear ?dst ?s)
 ($eval (not (equal? (quote ?obj) (quote ?dst))))
 ($eval (not (equal? (quote ?src) (quote ?dst))))
 then
 (clear ?src (move ?obj ?src ?dst ?s)))

;;; Trivial AND

(and2
 if 
 (on ?x1 ?x2 ?s)
 (on ?x3 ?x4 ?s)
 then
 (and 
  (on ?x1 ?x2 ?s)
  (on ?x3 ?x4 ?s)))

(and3
 if 
 (on ?x1 ?x2 ?s)
 (on ?x3 ?x4 ?s)
 (on ?x5 ?x6 ?s)
 then
 (and 
  (on ?x1 ?x2 ?s)
  (on ?x3 ?x4 ?s)
  (on ?x5 ?x6 ?s)))

ASSERTIONS

(clear table initial)
(on b c initial)
(on c a initial)
(on a table initial)

CODE

(define (ask-plan)
  (ask-top-level
   '(and (on c table (? plan)) (on b c (? plan)) (on a b (? plan)))
   (lambda (bindings)
     (pretty-print bindings)
     (printf "%a is the plan\n" (sublis* bindings '(? plan)))
     #t)))
