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