#!/usr/bin/env swipl % % PFC is a11 language extension for prolog.. there is so much that can be done in this language extension to Prolog % % Dec 13, 2035 % Douglas Miles % cls ; kill -9 %1 ; swipl -g "ensure_loaded(pack(logicmoo_base/t/examples/base/'sanity_abc.pfc'))." % was_module(header_sane,[]). :- include(test_header). :- if(prolog_load_context(module,user)). :- use_module(library(pfc)). :- endif. :- set_file_abox_module(user). :- autoload([verbose(false)]). :- set_prolog_flag(runtime_debug,3). :- printAll(mtProlog(_)). :- printAll(genlMt(_,_)). :- printAll(mtHybrid(_)). :- printAll(defaultAssertMt(_)). :- printAll(fileAssertMt(_)). % :- break. :- abolish(a11,0). :- abolish(b11,0). :- dynamic((a11/0,b11/0)). :- debug_logicmoo(logicmoo(_)). :- mpred_trace_msg(beginxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxx_abc). :- ensure_loaded(library(attvar_reader)). % :- rtrace,trace. sk1:attr_unify_hook(_,_). :- debug_logicmoo(_). :- nodebug_logicmoo(http(_)). :- debug_logicmoo(logicmoo(_)). % :- dynamic(sk1_in/1). :- read_attvars(true). :- debug_logicmoo(_). :- nodebug_logicmoo(http(_)). :- debug_logicmoo(logicmoo(_)). :- read_attvars(false). :- set_prolog_flag(assert_attvars,true). :- set_prolog_flag(expand_attvars,false). :- flag_call(runtime_debug=true). % :- rtrace,trace. sk1:attr_unify_hook(_,_). :- mpred_trace_exec. % :- call((rtrace)). :- assert_mu(sk1_in(avar([vn='Ex',sk1='SKF-6667']))). % :- listing_u(sk1_in/1). :- listing(sk1_in/1). :- must((sk1_in(Ex),get_attr(Ex,sk1,What),What=='SKF-6667')). :- read_attvars(true). :- must(clause_asserted_i(sk1_in(avar([vn='Ex',sk1='SKF-6667'])))). :- read_attvars(false). :- must( \+ clause_asserted_i(sk1_in(avar([vn='Ex',sk1='SKF-6667'])))). :- set_prolog_flag(assert_attvars,false). :- set_prolog_flag(expand_attvars,false). :- read_attvars(false). ca:- clause_asserted_i(sk1_in(avar([vn='Ex',sk1='SKF-6667']))). :- listing(ca). :- abolish(sk1_in/1). :- with_fc_mode(zdirect,must((get_fc_mode(xx,(xxxf,ax),DMode),DMode=zdirect))). sk1_in(avar([vn='Ex',sk1='SKF-666'])). :- ((sk1_in(Ex),oo_get_attr(Ex,sk1,What),What='SKF-666')). :- set_prolog_flag(expand_attvars,false). sk1_in(Ex)==>sk1_out(Ex). % :- set_prolog_flag(read_attvars,true). :- ((sk1_out(Ex),oo_get_attr(Ex,sk1,What),What=='SKF-666')). :- debug_logicmoo(_). :- nodebug_logicmoo(http(_)). :- debug_logicmoo(logicmoo(_)). % :- mpred_trace_exec. :- begin_pfc. :- dynamic(sk5_out/1). :- dynamic(sk5_in/1). % :- process_this_script. :- read_attvars(true). :- set_prolog_flag(assert_attvars,true). sk5_in(Ex)==>sk5_out(Ex). :- listing(pt). :- ain(sk5_in(avar([vn='ExIn',sk5='SKF-666']))). :- must(lookup_u(sk5_in(avar([vn='ZEx',sk5='SKF-666'])))). :- must(lookup_u(pt(sk5_in(avar([vn='IS',sk5='SKF-666'])),FOUND))),dmsg(fOUND=FOUND). ({member(Y,[1,2,3])}) ==> nondet_a_memb(Y). :- mpred_test(nondet_a_memb(1)). :- mpred_test(nondet_a_memb(3)). :- if((pfc_test_feature(localMt,X=1),X==1)). nondet. :- else. %:- baseKB:export(baseKB:nondet/0). %:- import(baseKB:nondet/0). :- listing(nondet/0). :- endif. (nondet, {member(Y,[1,2,3])}) ==> nondet_a(Y). :- mpred_test(nondet_a(1)). :- mpred_test(nondet_a(3)). functorDeclares(tFish). functorDeclares(tSwim). :- dmsg("tweety and chilly are fish."). tFish(iTweety). tFish(iChilly). :- dmsg("fish swim by default."). mdefault(( tFish(X) ==> tSwim(X))). /* :- header_sane:listing(nt/3). :- header_sane:listing(tSwim/1). :- header_sane:listing(pt/2). :- header_sane:listing(mdefault/1). :- header_sane:listing(spft/3). */ :- dmsg("make sure *both* can swim (this exposes a potential bug in monadic predicates)"). :- mpred_test((tSwim(iTweety))). :- mpred_test((tSwim(iChilly))). ~tSwim(iChilly). :- mpred_trace_exec. \+ tSwim(iTweety). :- mpred_test(\+ (tSwim(iTweety))). :- mpred_test(\+ ~(tSwim(iTweety))). :- mpred_test(\+ (tSwim(iChilly))). :- mpred_test( ~ (tSwim(iChilly))). :- sanity(\+ current_prolog_flag(mpred_te,false)). :- sanity(is_pfc_file). %:- listing(mtProlog). %:- listing(mtHybrid). :- mpred_trace_exec. :- listing(baseKB:mtHybrid/1). % :- must(uses_predicate(user,user,a11,0,_R)). :- (\+ call(a11)). :- listing(a11). :- (ain(a11 ==> b11)). :- (ain(a11)). % :- mpred_notrace_exec. %:- pp_DB. :- mpred_test(a11). :- mpred_test(b11). :- flag_call(runtime_debug=true). :- dynamic(bc_q/1). :- dynamic(bc_p/1). :- debug_logicmoo(logicmoo(_)). :- mpred_trace_msg("before trace"). % :- mpred_trace_exec. % :- begin_pfc. :- mpred_trace_msg("after trace"). :- debug_logicmoo(logicmoo(_)). :- mpred_trace_exec. :- (ain((bc_q(N) <- bc_p(N)))). :- ain(bc_p(a)). bc_p(b). :- must(call_u(bc_p(b))). %= nothing cached :- listing(bc_q/1). :- must((call_u(bc_q(b)))). %= something cached :- listing(bc_q/1). :- dynamic(default_01a/1). :- listing(mtHybrid). :- listing(mtProlog). (default_01a(P)/mpred_literal(P)) ==> (~( ~P) ==> P). default_01a((P ==> Q))/mpred_literal(Q) ==> (P, \+( ~Q) ==> Q). :- break. :- dumpST. :- throw(set_prolog_flag(gc,false_fc_loop)). % birds fly by default_01a. :- (ain(( default_01a((bird(X) ==> fly(X)))))). % here's one way to do an zisa hierarchy. % zisa = subclass. :- ain((zisa(C1,C2) ==> {P1 =.. [C1,X], P2 =.. [C2,X]}, (P1 ==> P2))). :- ain((zisa(canary,bird))). ==> zisa(penguin,bird). % penguins do not fly. penguin(X) ==> ( ~fly(X)). % chilly is a penguin. ==> penguin(chilly). % tweety is a canary. ==> canary(tweety). :- mpred_test(~fly(chilly)). :- mpred_test(fly(tweety)). % :- defaultAssertMt(User),listing(User:_). (tType(COL)==>{kb_local(COL/2)},% functorDeclares(COL), (t(COL,ext,X)<==>iza(X,COL))). tType(tFly). tType(tCanary). tType(tPenguin). tType(tBird). :- mpred_test(predicate_property(tBird(ext,_),dynamic)). genls(C1,C2)==> (iza(X,C1)==>iza(X,C2)). genls(tCanary,tBird). genls(tPenguin,tBird). :- dmsg("chilly is a penguin."). tPenguin(ext,iChilly). :- mpred_test((tBird(ext,iChilly))). :- dmsg("tweety is a canary."). tCanary(ext,iTweety). :- mpred_test((tBird(ext,iTweety))). :- dmsg("birds fly by default."). mdefault(( tBird(ext,X) ==> tFly(ext,X) )). :- mpred_test((tBird(ext,iTweety))). :- mpred_test((tFly(ext,iTweety))). :- dmsg("make sure chilly can fly"). :- mpred_test((iza(I,tFly),I=iChilly)). :- mpred_test((tBird(ext,iTweety))). :- listing([tFly/2,tBird/2,iza/2]). :- dmsg("make sure tweety can fly (and again chilly)"). :- mpred_test((tFly(ext,iTweety))). :- mpred_test((tFly(ext,iChilly))). never_retract_u(tBird(ext,iChilly)). :- dmsg("penguins do not tFly."). tPenguin(ext,X) ==> ~tFly(ext,X). :- dmsg("confirm chilly now cant fly"). :- mpred_test((\+ tFly(ext,iChilly))). :- mpred_test(( ~ tFly(ext,iChilly))). %= repropigate that chilly was a bird again (actualy this asserts) tBird(ext,iChilly). :- listing(tBird/2). %= the dmsg explains the difference between \+ and ~ :- dmsg("confirm chilly still does not fly"). :- mpred_test(( \+ tFly(ext,iChilly))). :- dmsg("confirm chilly still cant fly"). :- mpred_test(( ~ tFly(ext,iChilly))). /* % This wounld be a good TMS test it should throw.. but right now it passes wrongly tFly(ext,iChilly). :- dmsg("confirm chilly is flying penguin"). :- mpred_test(( tFly(ext,iChilly))). :- mpred_test(( tPenguin(ext,iChilly))). :- mpred_test((\+ ~tFly(ext,iChilly))). \+ tFly(ext,iChilly). :- dmsg("confirm chilly is a normal penguin who cant fly"). :- mpred_test((\+ tFly(ext,iChilly))). % fails rightly :- mpred_test(( tPenguin(ext,iChilly))). */ :- dmsg("chilly is no longer a penguin (hopefly the assertion above about him being a bird wont be removed)"). :- debug_logicmoo(_). :- mpred_trace_exec. :- debug_logicmoo(logicmoo(_)). :- mpred_test(tBird(ext,iChilly)). never_retract_u(tBird(ext,iChilly)). \+ tPenguin(ext,iChilly). :- mpred_test((tBird(ext,iChilly))). :- mpred_test(( \+ tPenguin(ext,iChilly))). :- dmsg("chilly is still a bird"). :- mpred_test((tBird(ext,iChilly))). :- dmsg("confirm chilly is flying bird"). :- mpred_test(( tFly(ext,iChilly))). :- repropagate(tBird(ext,iChilly)). :- dmsg("confirm chilly is flying bird"). :- mpred_test(( tFly(ext,iChilly))). :- mpred_test(( \+ tPenguin(ext,iChilly))). :- mpred_test(( \+ ~tFly(ext,iChilly))). :- test_retake.