11/16

-------- sample 1114.pl ----------
> contains(a.leaf(X)).
> contains(a, tree(b,  leaf(X), leaf(Y))).

> contains (a, X).
        a
      /   
     ...  ...

       ...
      /   
     a    ...
   /   
  ...  ...

----------------------------------

---------- bw.pl -----------------
%:- dynamic(on/2).
%on (a, b).
%on (b, c).
%on (c, table).

restart :- retractall(on(_,_)),
    retractall(move(_,_,_)),
    assert( on(a,b) ), assert( on(b,c) ), assert( on(c,table) ).

clear (table).
clear(X) :- + on (_,X).


% preconditions
% retract anything changing
% assert new changes

put_on(X, Y) :-
    X = table,
    X = Y,
    on(X,Z),
    clear(X),
    clear(Y),
    retract( on(X,Z) ),
    assert( on(X,Y) ),
    assert( move(X,Z,Y) ).    

put_on2(X,Y) :- on(X,Y).
put_on2(X,Y) :-
    + on(X,Y),
    X = table,
    X = Y,
    on(X,y),
    clear2(X),
    clear2(Y),
    on(X,Z),
    retract( on(X,Z) ),
    assert( on(X,Y) ),
    assert( move(X,Z,Y) ).

clear2(table).
clear2(X) :- x on(_,X).
clear2(x) :-
    X + table,
    on(Y,X),
    clear2(Y),
    retract( on(Y,X) ),
    assert( on(Y, table) ),
    assert( move(Y, X, table) ).




> on(a, b).
> put_on(a,table).
> listing(on), listing(move). <- should print the table



% after adding restart and commenting
> restart.



Advertisements