Did you know ... Search Documentation:
Pack logicmoo_utils -- prolog/logicmoo/redo_locally.pl
PublicShow source

This module allows drastic changes to prolog data to happen very temporarily. (to be reset or temporarily changed.) @author Douglas R. Miles @license LGPL

 locally_hide_each(:Fact, :Call) is nondet
Temporally Disable Fact with Fact :- !,fail.

use locally_hide_each/3 if respecting Non-determism is important (slightly slower?)

 locally_hide_each(:Fact, :Call) is nondet
Temporally Disable Fact with Fact :- !,fail.

But Ensure Non-determism is respected (slightly slower?)

uses each_call_cleanup/3 instead of setup_call_cleanup/3

 locally_each(:Effect, :Call) is nondet
Temporally have :Effect (see locally/2)

But Ensure Non-determism is respected (effect is undone between Redos)

uses each_call_cleanup/3 instead of setup_call_cleanup/3 (slightly slower?)

for example,

locally_each/2 works (Does not throw)

?- current_prolog_flag(xref,Was), locally_each(set_prolog_flag(xref,true), assertion(current_prolog_flag(xref,true));assertion(current_prolog_flag(xref,true))), assertion(current_prolog_flag(xref,Was)),fail. ===

locally/2 does not work (it throws instead)

?- current_prolog_flag(xref,Was), locally(set_prolog_flag(xref,true), assertion(current_prolog_flag(xref,true));assertion(current_prolog_flag(xref,true))), assertion(current_prolog_flag(xref,Was)),fail. ===

 locally(:Effect, :Call) is nondet
Effect may be of type:

set_prolog_flag - Temporarily change prolog flag

op/3 - change op

$gvar=Value - set a global variable

Temporally (thread_local) Assert some :Effect

use locally_each/3 if respecting Non-determism is important (slightly slower?)

=== ?- current_prolog_flag(xref,Was), locally(set_prolog_flag(xref,true), assertion(current_prolog_flag(xref,true))), assertion(current_prolog_flag(xref,Was)). ===

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 locally_tl(Arg1, Arg2)
 locally_hide(Arg1, Arg2)
 local_override(Arg1, Arg2)
 w_o_c(Arg1)
 w_o_c(Arg1, Arg2)