1/*  LogicMOO User Modules Setup
    2%
    3%
    4% Dec 13, 2035
    5% Douglas Miles
    6
    7*/
    8:- module(logicmoo_typesystem,
    9 [
   10 % logicmoo_user_stacks/0,
   11 /*op(1199,fx,('==>')),
   12 op(1190,xfx,('::::')),
   13 op(1180,xfx,('==>')),
   14 op(1170,xfx,'<==>'),
   15 op(1160,xfx,('<-')),
   16 op(1150,xfx,'=>'),
   17 op(1140,xfx,'<='),
   18 op(1130,xfx,'<=>'),
   19 op(600,yfx,'&'),
   20 op(600,yfx,'v'),
   21 op(350,xfx,'xor'),
   22 op(300,fx,'~'),
   23 op(300,fx,'-')*/  ]).   24
   25:- set_module(class(library)).   26
   27/*
   28
   29:- current_prolog_flag(readline,Was),writeln(readline=Was).
   30:- if(exists_source(library(editline))).
   31:- set_prolog_flag(readline,editline).
   32:- endif.
   33% :- set_prolog_flag(readline,true).
   34
   35:- if(current_prolog_flag(readline,editline)).
   36:- system:ensure_loaded(library(readline)).
   37:- listing(prolog:history/2).
   38:- abolish(prolog:history/2).
   39:- system:reconsult(library(editline)).
   40:- else.
   41:- if(exists_source(library(readline))).
   42:- if(exists_source(library(editline))).
   43:- system:ensure_loaded(library(editline)).
   44:- listing(prolog:history/2).
   45:- abolish(prolog:history/2).
   46:- endif.
   47:- unload_file(library(readline)).
   48:- system:consult(library(readline)).
   49:- endif.
   50:- endif.
   51:- current_prolog_flag(readline,Was),writeln(readline=Was).
   52*/
   53
   54:- set_prolog_flag(report_error,true).   55%:- set_prolog_flag(access_level,system).
   56%:- set_prolog_flag(debug_on_error,true).
   57:- set_prolog_flag(optimise,false).   58:- set_prolog_flag(last_call_optimisation,false).   59/*
   60:- set_prolog_flag(fileerrors,false).
   61:- set_prolog_flag(debug,true).
   62:- set_prolog_flag(gc,true).
   63:- debug.
   64*/
   65
   66:- '$set_source_module'(baseKB).   67:- use_module(library(pfc)).   68
   69use_shared_module(USM):- with_no_mpred_expansions(baseKB:reexport(USM)).
   70
   71:- set_prolog_flag(pfc_booted,false).   72:- current_prolog_flag(unsafe_speedups,_)->true;set_prolog_flag(unsafe_speedups,true).   73:- use_shared_module(library(gvar_syntax)).   74:- use_shared_module(library(dictoo)).   75%:- use_shared_module(library(pfc_lib)).
   76%:- use_shared_module(library(xlisting)).
   77:- with_no_mpred_expansions(use_shared_module(logicmoo_swilib)).   78
   79%:- kb_shared(col_as_isa/1). % members are used thru  isa(ELEM,COL).
   80%:- kb_shared(col_as_static/1). % hard coded like: compound/1
   81%:- kb_shared(col_as_unary/1). % written as COL(ELEM)
   82
   83
   84:- kb_shared(mudToCyc/2).   85:- kb_shared(quotedIsa/2).   86:- kb_shared(rtReformulatorDirectivePredicate/1).   87:- kb_shared(tCol/1).   88:- kb_shared(tSet/1).   89:- kb_shared(ttRelationType/1).   90:- kb_shared(type_checking/0).   91:- kb_shared(disjointWith/2).   92:- kb_shared(isa/2).   93:- kb_shared(genlsFwd/2).   94:- kb_shared(genls/2).   95:- kb_shared(meta_argtypes/1).   96
   97
   98:- gripe_time(60,baseKB:ensure_loaded(library('logicmoo/plarkc/logicmoo_i_cyc_rewriting'))).   99
  100:- create_prolog_flag(mpred_te,true,[type(term),keep(false)]).  101%:- use_module(library(pfc_lib)).
  102%:- pfc_load_lib.
  103
  104/*
  105:- kb_shared(baseKB:prologSingleValued/1).
  106:- kb_shared(baseKB:never_assert_u/1).
  107:- kb_shared(baseKB:never_assert_u/1).
  108:- kb_shared(baseKB:never_retract_u/1).
  109:- kb_shared(baseKB:never_retract_u/2).
  110:- kb_shared(baseKB:mpred_prop/4).
  111:- kb_shared(baseKB:do_and_undo/2).
  112:- kb_shared(baseKB:spft/3).
  113:- kb_shared(baseKB:bt/2).
  114:- kb_shared(baseKB:hs/1).
  115:- kb_shared(baseKB:nt/3).
  116:- kb_shared(baseKB:pk/3).
  117:- kb_shared(baseKB:pt/2).
  118:- kb_shared(baseKB:que/2).
  119:- kb_shared(baseKB:pm/1).
  120:- kb_shared(baseKB:spft/3).
  121:- kb_shared(baseKB:tms/1).
  122*/
  123:- system:use_module(library(logicmoo/subclause_expansion)).  124:- system:use_module(library(logicmoo/virtualize_source)).  125:- system:use_module(library(logicmoo/filesystem)).  126
  127wsce(W):- with_subclause_expansion((set_how_virtualize_file(bodies,W,0),baseKB:consult(W))).
  128:- wsce(library('logicmoo/typesystem/mpred_agenda.pl')).  129:- wsce(library('logicmoo/typesystem/mpred_hooks.pl')).  130:- wsce(library('logicmoo/typesystem/mpred_storage.pl')).  131:- wsce(library('logicmoo/typesystem/mpred_stubs.pl')).  132:- wsce(library('logicmoo/typesystem/mpred_type_isa.pl')).  133:- wsce(library('logicmoo/typesystem/mpred_type_constraints.pl')).  134:- wsce(library('logicmoo/typesystem/mpred_type_args.pl')).  135:- wsce(library('logicmoo/typesystem/mpred_type_wff.pl')).  136:- wsce(library('logicmoo/typesystem/mpred_type_naming.pl')).  137
  138
  139:- set_prolog_flag(pfc_booted,false).  140
  141
  142:- set_prolog_flag(pfc_booted,true).  143:- set_prolog_flag(read_attvars,false).  144
  145:- ((hook_database:call(asserta_if_new,(ereq(G):- !, call_u(G))))).  146:- after_boot((wdmsg(after_boot),hook_database:call(asserta_new,(ereq(G):- !, call_u(G))))).  147
  148
  149
  150
  151:- set_prolog_flag(expect_pfc_file,soon).  152% :- rtrace, visible(-all),visible(+exception).
  153:-  call(prolog_statistics:time,((ensure_loaded(baseKB:library(logicmoo/pfc/'autoexec.pfc'))))).  154:- set_prolog_flag(expect_pfc_file,never).  155
  156
  157:- sanity(\+ is_pfc_file).  158
  159
  160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  161% SETUP KB EXTENSIONS
  162%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  163
  164%:- '$set_source_module'(baseKB).
  165%:- '$set_typein_module'(baseKB).
  166
  167%:- clause(user:term_expansion(I,O),M:Body).
  168%:- clause(system:term_expansion(I,O),M:Body).
  169
  170
  171% 	 	 
  172%% m1 is semidet.
  173%
  174% Hook To [checkkb:m1/0] For Module Logicmoo_snark.
  175% Module Secondary Helper.
  176%
  177%:- add_library_search_path('./mpred_online/',[ '*.pl']).
  178checkKB:m1:- gripe_time(40,wsce(library(xlisting_web))),if_defined(ensure_webserver), make,list_undefined.
  179
  180% :- hook_message_hook.
  181% :- set_prolog_flag(verbose_autoload,false).
  182% :- set_prolog_flag(verbose_load,true).
  183% m9   :-asserta_if_new((user:term_expansion(I,O):- lmbase_expansion(term,user,I,O))).
  184%m31 :-   (F = mpred/_),foreach(must(baseKB:mpred_is_impl_file(F)),must_det_l((dmsg(list_file_preds(F)),wsce(F),export_file_preds(F),list_file_preds(F)))).
  185%m32:- rtrace(ensure_mpred_system).
  186% m33:- must(filematch_ext(['',mpred,ocl,moo,plmoo,pl,plt,pro,p,'pl.in',pfc,pfct],logicmoo_user:pfc/mpred,W)),dmsg(W),!.
  187
  188%:-export(m2/0).
  189% m2:- ensure_mpred_file_loaded(logicmoo(pfc/relationAllExists)).
  190
  191% :-ain(((P,Q,z(_))==>(p(P),q(Q)))).
  192%:-export(m3/0).
  193% m3:- put_variable_names( ['P'=P,'Q'=Q]), R = (==>((P,Q,z(_)),(p(P),q(Q)))),  renumbervars(write_functor,R,O), writeq(O).
  194%   put_variable_names( ['P'=P,'Q'=Q]), R = (==>((P,Q,z(_)),(p(P),q(Q)))), write_term(R,[numbervars(true),protray(_)]),renumbervars_prev(R,O).
  195
  196%:-export(m4/0).
  197
  198%m5 :- enable_mpred_system(baseKB).
  199
  200
  201ensure_autoexec:- !. % call_u(consult(logicmoo(pfc/'autoexec.pfc'))).
  202
  203%:- use_listing_vars.
  204%:- autoload([verbose(false)]).
  205%:- use_listing_vars.
  206%:- nop((autoload,scan_for_varnames)).
  207
  208
  209:- module_transparent((mpred_load_restore_file/1,mpred_load_restore_file/1,mpred_save_restore_file/1)).  210
  211
  212mpred_load_restore_file(never):- !,ensure_autoexec,!.
  213mpred_load_restore_file(File):- absolute_file_name(File,AFN),AFN\=File,!,mpred_load_restore_file(AFN).
  214mpred_load_restore_file(File):- \+ exists_file(File),
  215  ensure_autoexec, !,
  216  mpred_save_restore_file(File),!.
  217
  218mpred_load_restore_file(File):-
  219  must_det_l((
  220  time_file(File,Time),
  221  qcompile(File),
  222  wsce(File),
  223   ((\+ (baseKB:loaded_file_world_time(N,_,NewTime),NewTime>=Time)) ->true ;
  224    (
  225    ignore((baseKB:loaded_file_world_time(N,_,NewTime),NewTime>Time,
  226     with_umt(baseKB,ensure_mpred_file_loaded(N)),fail)),
  227    mpred_save_restore_file('some_test.pl~'))))),!.
  228
  229mpred_save_resore_predicate(M:H,AFN):-
  230   functor(H,F,A),
  231   format('~N:- multifile(~q:(~q)/~q).~n',[M,F,A]),
  232   once((prolog_listing:list_declarations(M:H,M))),
  233   clause(M:H,B,R), 
  234   once(clause_property(R,file(AFN));\+clause_property(R,file(_))),
  235   ignore(once(get_clause_vars(H:-B))),
  236   prolog_listing:portray_clause((H:-B)).
  237
  238
  239mpred_save_restore_file(File):- 
  240 must_det_l((   
  241  absolute_file_name(File,AFN),
  242   tell(AFN), 
  243   format('~N:- ~q.~n',['$set_source_module'(basePFC)]),
  244   format('~N:- style_check(-singleton).'),  
  245   listing(_),
  246   flush_output,
  247   format('~N:- style_check(-singleton).'),
  248   format('~N:- ~q.~n',['$set_source_module'(baseKB)]),
  249   ignore((
  250   cur_predicate(_,baseKB:H),
  251    mpred_save_resore_predicate(baseKB:H,AFN),
  252   flush_output,
  253   fail)),!,
  254      format('~N:- ~q.~n',['$set_source_module'(baseKB)]),
  255      format('~N:- style_check(-singleton).~n'),
  256      listing(baseKB:loaded_file_world_time/3),
  257      flush_output,
  258   told)),!.
  259
  260:- fixup_exports.  261
  262:- baseKB:qsave_lm(lm_repl4).