#!/usr/bin/env swipl % % PFC is a language extension for prolog.. there is so much that can be done in this language extension to Prolog % % Dec 13, 2035 % Douglas Miles % Tests Retraction undoes Backchaining memo idea is working % was_module(bc_01a,[]). :- include(test_header). % :- baseKB:ensure_loaded(library('pfclib/system_autoexec.pfc')). :- set_prolog_flag(retry_undefined, kb_shared). :- dynamic(bc_q/1). :- dynamic(bc_p/1). :- if(false). ==> never_assert_u(bc_q(a),too_early). % dont assert the "general" backchain rule as a forward chain! ==> never_assert_u((pt(bc_p(A), rhs([bc_q(A)]))),too_early). :- endif. :- (ain((bc_q(N) <- bc_p(N)))). bc_q(N) <- bc_p(N). :- listing(bt/2). :- listing(pt/2). :- listing(bc_q/1). :- printAll(( clause_u(bc_q(_),NT),ignore(compound(NT)))). bc_p(a). bc_p(b). :- listing(bc_p/1). :- if(false). \+ never_assert_u(bc_q(a),too_early). \+ never_assert_u((pt(bc_p(A), rhs([bc_q(A)]))),too_early). :- endif. :- mpred_test(call_u(bc_p(b))). %= nothing cached :- listing(bc_q/1). :- mpred_test(\+ clause(bc_q(_),true)). :- mpred_test(((bc_q(b)))). %= something cached :- listing(bc_q/1). :- mpred_test( clause_u(bc_q(_),true)). % Are we cleaning up backchains? :- xlisting(bc_q/1). :- (((mpred_withdraw(((bc_q(N) <- bc_p(N))))))). :- ignore(mpred_why(bc_q(A)<-bc_p(A))). :- mpred_trace_exec. :- (((mpred_withdraw(((bc_q(N) <- bc_p(N))))))). % :- rtrace((((mpred_withdraw(((bc_q(N) <- bc_p(N)))))))). :- ignore(mpred_why(bc_q(A)<-bc_p(A))). :- ignore(mpred_why(bc_q(b))). :- listing(bc_q/1). :- mpred_test(((mpred_withdraw(((bc_q(N) <- bc_p(N))))))). %= nothing cached :- listing(bc_q/1). :- mpred_test(((mpred_withdraw(((bc_q(N) <- bc_p(N))))), show_failure((\+ clause_u(bc_q(_),true))))). :- mpred_test(\+ clause_u(bc_q(_),true)). :- xlisting(bc_q/1). end_of_file. :- listing(bc_q/1). :- ain(bc_p(a)). :- \+ is_asserted(bc_q(a)). ?- mpred_test(bc_p(a)). :- is_asserted(bc_q(a)). :- pp_DB.