> (all-blocks '((a on table) (b on a))) (A B) > (top-free-blocks '((a on table) (b on a))) (B) > (top-free-blocks '((a on table) (b on table))) (A B) > (setq s '((a on table) (b on c) (c on table) (d on a))) ((a on table) (b on c) (c on table) (d on a)) > (all-blocks s) (b c a d) > (top-free-blocks s) (b d)
(defun all-objects (state) (cond ((null state) nil) (t (union (remove 'on (car state)) (all-objects (cdr state))))) ) (defun all-blocks (state) (remove 'table (all-objects state))) (defun top-free-blocks (state) (let ((blocks (all-blocks state))) (dolist (x state) (if (not (eq 'table (third x))) (setq blocks (remove (third x) blocks)))) blocks))