1:- module(attvar_reader, [read_attvars/1,read_attvars/0,install_attvar_expander/1,uninstall_attvar_expander/1]).    2:- set_module(class(library)).    3/*  Logicmoo Debug Tools
    4% ===================================================================
    5% File 'logicmoo_util_varnames.pl'
    6% Purpose: An Implementation in SWI-Prolog of certain debugging tools
    7% Maintainer: Douglas Miles
    8% Contact: $Author: dmiles $@users.sourceforge.net ;
    9% Version: 'logicmoo_util_varnames.pl' 1.0.0
   10% Revision: $Revision: 1.1 $
   11% Revised At:  $Date: 2002/07/11 21:57:28 $
   12% ===================================================================
   13*/
   14:- create_prolog_flag(assert_attvars,false,[keep(true)]).   15:- create_prolog_flag(read_attvars,false,[keep(true)]).   16:- module_transparent((read_attvars/1,read_attvars/0)).   17
   18:- use_module((toplevel_variable_names)).   19:- use_module((attvar_serializer)).   20
   21
   22:- multifile(lmcache:use_attvar_expander/1).   23:- dynamic(lmcache:use_attvar_expander/1).   24
   25:- multifile(lmcache:never_use_attvar_expander/1).   26:- dynamic(lmcache:never_use_attvar_expander/1).
 install_attvar_expander(+FileOrModule) is det
Installs Attvar Expander to File Or Module
   32install_attvar_expander(M):- lmcache:use_attvar_expander(M),!.
   33install_attvar_expander(M):-
   34  dmsg(install_attvar_expander(M)),
   35  asserta(lmcache:use_attvar_expander(M)),
   36  system:multifile(M:term_expansion/4),
   37  system:module_transparent(M:term_expansion/4),
   38  system:dynamic(M:term_expansion/4),
   39  asserta(((M:term_expansion(I,P,O,P):- system_expanded_attvars(M:term,P,I,O)))),
   40  system:multifile(M:goal_expansion/4),
   41  system:module_transparent(M:goal_expansion/4),
   42  system:dynamic(M:goal_expansion/4),
   43  set_prolog_flag(read_attvars,true),
   44  set_prolog_flag(assert_attvars,true),
   45  asserta(((M:goal_expansion(I,P,O,P):- system_expanded_attvars(M:goal,P,I,O)))),
   46  !.
 uninstall_attvar_expander(+FileOrModule) is det
Uninstalls Attvar Expander from File Or Module
   53uninstall_attvar_expander(M):-
   54  retract(lmcache:use_attvar_expander(M)),!,
   55  ignore(retract((M:goal_expansion(I,P,O,P):- system_expanded_attvars(M:goal,P,I,O)))),
   56  ignore(retract((M:term_expansion(I,P,O,P):- system_expanded_attvars(M:term,P,I,O)))),
   57  (lmcache:use_attvar_expander(M)->true;set_prolog_flag(read_attvars,false)).
   58uninstall_attvar_expander(_):-set_prolog_flag(read_attvars,false).
   59  
   60  
   61
   62read_attvars:- read_attvars(true).
   63
   64read_attvars(TF):- 
   65  set_prolog_flag(read_attvars,TF),
   66%  set_prolog_flag(assert_attvars,TF),
   67  prolog_load_context(module,M),
   68  (TF==true->
   69     install_attvar_expander(M);
   70     uninstall_attvar_expander(M)).
   71
   72
   73
   74user:expand_query(Goal, Expanded, Bindings, ExpandedBindings):- fail,
   75      prolog_load_context(module,LC),
   76      \+ lmcache:never_use_attvar_expander(LC),
   77      current_prolog_flag(read_attvars,true),
   78      \+ current_prolog_flag(read_attvars_toplevel,false),
   79      \+ current_prolog_flag(xref,true), 
   80      Struct= ['$variable_names'|Bindings],
   81      deserialize_attvars(Struct,Goal,Expanded),
   82      [_|ExpandedBindings] = Struct.
   83
   84
   85:- fixup_exports.