Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "logicmoo_utils"

Title:Common predicates that are used throughout LogicMOO Software
Rating:Not rated. Create the first rating!
Latest version:3.1.5
SHA1 sum:59446572c271a6333062ad865141d7d3027850fb
Author:Douglas Miles http://www.linkedin.com/in/logicmoo
Maintainer:logicmoo https://github.com/logicmoo/
Packager:logicmoo/LogicMoo https://github.com/logicmoo/
Home page:https://github.com/logicmoo/logicmoo_utils
Download URL:https://github.com/logicmoo/logicmoo_utils/release/*.zip
Requires:predicate_streams

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
1.1.1128cca72f669d031880b4c2359d46b98a01bb467521https://github.com/TeamSPoon/logicmoo_utils.git
1.1.1153c81bb8c4fc8330f0691f8b2a3269dd7ea361c161https://github.com/TeamSPoon/logicmoo_utils.git
1.1.1177b85fb231634698a87e688601e9a914bf322e6201https://github.com/TeamSPoon/logicmoo_utils.git
1.1.1181cbdefcff57a09946e76e15ba579d527487d64061https://github.com/TeamSPoon/logicmoo_utils.git
36cd47768cb6d59930fa1f90096403f4c31ed6702https://github.com/TeamSPoon/logicmoo_utils.git
403bdfc4a4ccb4de536c1ee089645fb46ea2c1c71https://github.com/TeamSPoon/logicmoo_utils.git
d3ca9ec3502c228f40aaaddaccc2250beed0bf8c1https://github.com/TeamSPoon/logicmoo_utils.git
f3ff0f59a2a20516181520048e2258f3814f37451https://github.com/TeamSPoon/logicmoo_utils.git
1.2.1110d0d534c66d69c97b6c218253642949421cae41f1https://github.com/TeamSPoon/logicmoo_utils.git
106dd8e84510932983c5f19001808a553ceb59652https://github.com/TeamSPoon/logicmoo_utils.git
753eea274b5fb5d7c820275d8472cc44dcd181b72https://github.com/TeamSPoon/logicmoo_utils.git
7a06476933e9e1c417d81b99d27154143f2f6abb1https://github.com/TeamSPoon/logicmoo_utils.git
8a351dcb0b8db838ae848fa26dc1de42910285101https://github.com/TeamSPoon/logicmoo_utils.git
c97ba69e594d59b613c2d64f1647fe5e456eff4f2https://github.com/TeamSPoon/logicmoo_utils.git
f5a21c2a5456ad7e86b6db870c79bf720a1d946a4https://github.com/TeamSPoon/logicmoo_utils.git
1.4.1113b6993f32576b571e7add3c22c89ff3e1b4b895d1https://github.com/TeamSPoon/logicmoo_utils.git
3bb0515200b11ba77b61c77891dff032816aa49c1https://github.com/TeamSPoon/logicmoo_utils.git
cad1015cc57e54901920f17165a4eb2aa5f727973https://github.com/TeamSPoon/logicmoo_utils.git
de9b2834eee736cc104ecf6fafed0e66dfb880603https://github.com/TeamSPoon/logicmoo_utils.git
1.5.6662a432ae338479b0f265a6d9c60df2c40fa5e38245https://github.com/TeamSPoon/logicmoo_utils.git
638bb6cad4734d7c9494ecf3045dffe155a6d4184https://github.com/TeamSPoon/logicmoo_utils.git
70b50582093e0fee5095909ceca866e177b7cc116https://github.com/TeamSPoon/logicmoo_utils.git
7337574fc89b956615d05b26c5f6914500f376ac2https://github.com/TeamSPoon/logicmoo_utils.git
a2b70420bead989d1c042bc79ebe71be9cc4825d1https://github.com/TeamSPoon/logicmoo_utils.git
b935f82e676a44ffd34f6535d6d547f2a5f9fca41https://github.com/TeamSPoon/logicmoo_utils.git
c3c7bd0fb8c6f35b96f1ea0e7faf9c5f651639f51https://github.com/TeamSPoon/logicmoo_utils.git
2.0.17099c9e151ad2ece23d82e42a605ddcb5a2b14832https://github.com/TeamSPoon/logicmoo_utils.git
ae6ec053b0c45f197b5fb899c4971dd5a7008dde1https://github.com/TeamSPoon/logicmoo_utils.git
f89c500fddda26bc294978a4dc11921369774b6c1https://github.com/TeamSPoon/logicmoo_utils.git
fda8081fe200dec3f6d784ec81e109fa1db3b2633https://github.com/TeamSPoon/logicmoo_utils.git
2.0.315dd5682392fe763c0b101aa439b13beedb6bc979https://github.com/TeamSPoon/logicmoo_utils.git
3818e7afd5b9ef3759c37bc2ff6b26d87e3b32201https://github.com/TeamSPoon/logicmoo_utils.git
5199dad702652f586779e91dae6d9ea40c0c43d31https://github.com/TeamSPoon/logicmoo_utils.git
a2bb81f2d21b2bd165782ab198ebec726b793f673https://github.com/TeamSPoon/logicmoo_utils.git
a89fd2ec263a12a1bdeeb31aabf864c8abea15ea2https://github.com/TeamSPoon/logicmoo_utils.git
ac3049069c97bd879d7fa4908f7eb7538b34673c1https://github.com/TeamSPoon/logicmoo_utils.git
bcf33b4424cc9098844e9d2d2dfcb0775b01f4171https://github.com/TeamSPoon/logicmoo_utils.git
c4c0462b8ea7bfccfa6f110fcd214cd171ef62633https://github.com/TeamSPoon/logicmoo_utils.git
3.0.30f0e95e2a82da927343dad20eef214d9b15f24f25https://github.com/TeamSPoon/logicmoo_utils.git
5bf4e5530f51b48d6b67c4ed112d2b3a7b322e451https://github.com/TeamSPoon/logicmoo_utils.git
62eda95aef1c7acc5f11754f4af1f9a45c9aad911https://github.com/TeamSPoon/logicmoo_utils.git
6a011f8b928086a61ca3e5ba8ed3adc80519b9aa1https://github.com/TeamSPoon/logicmoo_utils.git
91fdac8db54e64e46619a0ff10ce867673115efe2https://github.com/TeamSPoon/logicmoo_utils.git
940da95101d8b28b71df4017032ff7634f886b4c1https://github.com/TeamSPoon/logicmoo_utils.git
9b0afc71bb77350588f98efc64504344f7d838825https://github.com/TeamSPoon/logicmoo_utils.git
fc6ae3a2fceeba23713e9db40d40e06297757f542https://github.com/TeamSPoon/logicmoo_utils.git
3.1.3da60f64236fba4724b29664ace83b8a9e668a8146https://github.com/TeamSPoon/logicmoo_utils.git
3.1.4067955d845a62b8280353fb778a43888f8c2886a1https://github.com/TeamSPoon/logicmoo_utils.git
1506a5def843e7437d427f727f9f52dc6b62ac732https://github.com/TeamSPoon/logicmoo_utils.git
1cba0ef78f5bf337f74af8ac586a30fc03063c742https://github.com/TeamSPoon/logicmoo_utils.git
57688d27a2ec4b7b34dbc6a3203ac6029a10e6dc10https://github.com/TeamSPoon/logicmoo_utils.git
5ac0c84f746e0ed01dd2cadd3d57804c767f84a11https://github.com/TeamSPoon/logicmoo_utils.git
7c1f217da74391f48abf842dfb75efeb3ffc429b2https://github.com/TeamSPoon/logicmoo_utils.git
9a370d6d07bc618cf30c86edd23fe5e341e58d4d2https://github.com/TeamSPoon/logicmoo_utils.git
cc0118c996b12744db039ebe5fccbdef1f9b02591https://github.com/TeamSPoon/logicmoo_utils.git
f8a75c0dec45ff8e4c8510f399105a3f725de2871https://github.com/TeamSPoon/logicmoo_utils.git
f96cfc9bbc0d176790eb54f4165ca03ff615f2d91https://github.com/TeamSPoon/logicmoo_utils.git
3.1.559446572c271a6333062ad865141d7d3027850fb20https://github.com/TeamSPoon/logicmoo_utils.git

Common predicates used by external Logicmoo Utils

![Build Status](https://travis-ci.org/logicmoo/logicmoo_utils) master ![Build Status](https://travis-ci.org/logicmoo/logicmoo_utils) default

Installation using SWI-Prolog 8.1.x or later (due to duplicate transitive deps failing in earlier versions):

`?- pack_install('https://github.com/logicmoo/logicmoo_utils.git'). `

Control local side effects on each REDO

Example usages:



 % Wrap `quietly/1` over parts of your code you no longer need to stepped thru.
 % This is a *nondeterministic* version of notrace/1 !  (Instead of like once/1)
 quietly(Goal):-
    tracing ->
      each_call_cleanup(notrace,Goal,trace);
      Goal.
    
            
 % Scope *when* a prolog flag is set
 with_prolog_flag(Flag,Value,Goal):-
    current_prolog_flag(Flag,Was),
     each_call_cleanup(
         set_prolog_flag(Flag,Value),
          Goal,
           set_prolog_flag(Flag,Was)).
  

 % Trace non interactively *sometimes*
 rtrace(Goal):-
    ( tracing-> Undo=trace ; Undo = notrace ),
    '$leash'(OldL, OldL), '$visible'(OldV, OldV),
    each_call_cleanup(
         (notrace,visible(+all),leash(-all),leash(+exception),trace),
         Goal,
         (notrace,'$leash'(_, OldL),'$visible'(_, OldV),Undo)).

Trace with your eyeballs instead of your fingers


?- use_module(library(logicmoo_utils)).
true.

?- rtrace(member(X,[1,2,3])).
   Call: (9) lists:member(_8730, [1, 2, 3])
   Unify: (9) lists:member(_8730, [1, 2, 3])
   Exit: (9) lists:member(1, [1, 2, 3])
X = 1 ;
   Redo: (9) lists:member(_8730, [1, 2, 3])
   Exit: (9) lists:member(2, [1, 2, 3])
X = 2 ;
   Redo: (9) lists:member(_8730, [1, 2, 3])
   Exit: (9) lists:member(3, [1, 2, 3])
X = 3.

?-  rtrace(member(X,[1,2,3])),member(Y,[4,5]).
   Call: (10) lists:member(_10508, [1, 2, 3])
   Unify: (10) lists:member(_10508, [1, 2, 3])
   Exit: (10) lists:member(1, [1, 2, 3])
X = 1,
Y = 4 ;
X = 1,
Y = 5 ;
   Redo: (10) lists:member(_10508, [1, 2, 3])
   Exit: (10) lists:member(2, [1, 2, 3])
X = 2,
Y = 4 ;
X = 2,
Y = 5 ;
   Redo: (10) lists:member(_10508, [1, 2, 3])
   Exit: (10) lists:member(3, [1, 2, 3])
X = 3,
Y = 4 ;
X = 3,
Y = 5.

?- rtrace((member(X,[1,2,3]),member(Y,[4,5]))).
   Call: (10) lists:member(_11854, [1, 2, 3])
   Unify: (10) lists:member(_11854, [1, 2, 3])
   Exit: (10) lists:member(1, [1, 2, 3])
   Call: (10) lists:member(_11872, [4, 5])
   Unify: (10) lists:member(_11872, [4, 5])
   Exit: (10) lists:member(4, [4, 5])
X = 1,
Y = 4 ;
   Redo: (10) lists:member(_11872, [4, 5])
   Exit: (10) lists:member(5, [4, 5])
X = 1,
Y = 5 ;
   Redo: (10) lists:member(_11854, [1, 2, 3])
   Exit: (10) lists:member(2, [1, 2, 3])
   Call: (10) lists:member(_11872, [4, 5])
   Unify: (10) lists:member(_11872, [4, 5])
   Exit: (10) lists:member(4, [4, 5])
X = 2,
Y = 4 ;
   Redo: (10) lists:member(_11872, [4, 5])
   Exit: (10) lists:member(5, [4, 5])
X = 2,
Y = 5 ;
   Redo: (10) lists:member(_11854, [1, 2, 3])
   Exit: (10) lists:member(3, [1, 2, 3])
   Call: (10) lists:member(_11872, [4, 5])
   Unify: (10) lists:member(_11872, [4, 5])
   Exit: (10) lists:member(4, [4, 5])
X = 3,
Y = 4 ;
   Redo: (10) lists:member(_11872, [4, 5])
   Exit: (10) lists:member(5, [4, 5])
X = 3,
Y = 5.

This is a miniture part of a very large debugging library... Some better parts of that library are not yet added.

Here are current uses:

?- use_module(library(logicmoo_utils)).

Wrap must/1 over parts of your code you do not trust yet. If your code fails.. it will rewind to your entry block (at the scope of this declaration) and invoke rtrace/1 . If there are 50 steps to your code, it will save you from pushing creep 50 times. Instead it turns off the leash to allow you to trace with your eyeballs instead of your fingers


:- must(member(3,[4,5])).

..... TODO Doc this .....




Wrap `sanity/1` over parts of your code you want to turn on/off that is only usefull for slow debugging

```prolog

:- sanity(sleep(10)).

..... TODO Doc this .....

Wrap nop/1 over parts of your code you do not want to quickly comment out yet not break syntax. Defined as:


:- meta_predicate nop(0).

nop(_).

..... TODO Doc this .....

no_repeats

New ways to avoid duplicate solutions


?- use_module(library(logicmoo_utils)).

?- no_repeats( X , member(X-Y,[3-2,1-4,1-5,2-1])).
% X = 3, Y = 2 ;
% X = 1, Y = 4 ;
% X = 2, Y = 1.


 ?- no_repeats(member(X,[3,1,1,1,3,2])).
% X = 3 ;
% X = 1 ;
% X = 2.

loop_check

New simple loop checking

Allows code to declare special locations that loop prevention will occur

?- use_module(library(logicmoo_utils)).
true.

?-  TODO Doc this

sub_clause_expansion


:- use_module(library(file_scope)).

:- set_prolog_flag_until_eof(access_level, system).

:- assert_until_eof(( term_expansion(.,.) :- .. )).

hook_hybrid

Hook and/or override assert, retract, call, clause, erase, etc for specific predicates

?- use_module(library(hook_database)).

true.

?-  TODO Doc this

clause_attvars

An alternate interface to the clause database to allow attributed variables to be asserted/read

?- use_module(library(hook_database)).
true.

?-  TODO Doc this

attvar_reader

?- use_module(library(hook_database)).
true.

?-  TODO Doc this

with_thread_local

Call a Goal with local assertions

locally_each( :Effect, :Call) is nondet.

Temporally have :Effect (see locally/2)

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

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 is little less carefull so it should 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)).

:- set_prolog_flag_until_eof(access_level,system).

:- assert_until_eof(( term_expansion(.,.) :- .. )).



# Utilities to open various objects for read/write

```prolog
?- use_module(library(logicmoo_utils)).

mass wildcard expansions

?- use_module(library(logicmoo_utils)).

Not obligated to maintain a git fork just to contribute

( Please ask to be added to logicmoo and Contribute directly ! )

I really dislike having tons of forks that are several commits behind the main git repo.

Rather just give you commit access (feel free to work from a branch)

Still, we wont stop you from doing it the Fork+PullRequest method

BSD 2-Clause License

Copyright (c) 1997 - 2018 logicmoo and Douglas Miles <logicmoo@gmail.com>

Some TODOs

Document this pack!


Write tests

./must_sanity.pl
./hook_database.pl
./file_scope.pl
./logicmoo_startup.pl
./logicmoo_common.pl
./no_repeats/no_repeats.pl
./loop_check/no_loops.pl

./scope_locally/with_no_x.pl
./scope_locally/with_thread_local.pl
./scope_locally/each_call_cleanup.pl

./expand_finer/subclause_expansion.pl

./file_utils/script_files.pl
./xlisting/xlisting_web/logicmoo_run_clio.pl
./xlisting/xlisting_web/mpred_rdf.pl
./xlisting/xlisting_web/logicmoo_run_pldoc.pl
./xlisting/xlisting_web/mpred_pldoc_util.pl
./xlisting/xlisting_web/xlisting_web.pl
./xlisting/xlisting_web/xlisting_web.pfc.pl
./xlisting/xlisting_web/swish_lib/render/html.pl
./xlisting/xlisting_web/xlisting_web_sanity_tests.pl
./xlisting/xlisting_web/logicmoo_run_swish.pl
./xlisting/listing_vars.pl
./xlisting/xlisting.pl
./debuggery/bugger.pl
./debuggery/block3.pl
./debuggery/frames.pl
./debuggery/dumpst.pl
./debuggery/rtrace.pl
./debuggery/unused_rtrace.pl
./debuggery/ucatch.pl
./debuggery/first.pl
./debuggery/util_supp.pl
./debuggery/dmsg.pl
./debuggery/sanity_tests.pl
./hybrid_db/attvar_serializer.pl
./hybrid_db/toplevel_variable_names.pl
./hybrid_db/call_from_module.pl
./hybrid_db/sanity_tests_cav.pl
./hybrid_db/predicate_inheritance.pl
./hybrid_db/retry_undefined.pl
./hybrid_db/virtualize_source.pl
./hybrid_db/lockable_vars.pl
./hybrid_db/clause_attvars.pl
./hybrid_db/sanity_tests.pl
./hybrid_db/attvar_reader.pl

./misc_lm/logicmoo_util_bb_env.pl
./misc_lm/logicmoo_util_bb_gvar.pl
./misc_lm/logicmoo_util_dra.pl
./misc_lm/logicmoo_util_ctx_frame.pl
./misc_lm/logicmoo_util_structs.pl
./misc_lm/logicmoo_util_butterfly.pl
./misc_lm/logicmoo_util_dlist.pl
./misc_lm/logicmoo_util_strings.pl
./misc_lm/logicmoo_util_engines.pl
./misc_lm/logicmoo_util_terms.pl
./file_utils/filestreams.pl
./file_utils/filesystem.pl

Contents of pack "logicmoo_utils"

Pack contains 327 files holding a total of 2.9M bytes.