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

Package "with_thread_local"

Title:Call a Goal with local assertions
Rating:Not rated. Create the first rating!
Latest version:1.2.111
SHA1 sum:d8733f5fd197869468497bbfdd97df36c63dd532
Author:Douglas R. Miles <logicmoo@gmail.com>
Maintainer:TeamSPoon https://github.com/TeamSPoon/
Packager:TeamSPoon/LogicMoo https://github.com/TeamSPoon/
Home page:https://github.com/TeamSPoon/with_thread_local
Download URL:https://github.com/TeamSPoon/with_thread_local/releases/*.zip
Requires:logicmoo_utils

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
1.1.11270ac617e658c5c1deda0ab278b54c50509aea3fc1https://github.com/TeamSPoon/with_thread_local.git
1.1.115fd6734e330581093fffca255fc1c9300283b1e9d1https://github.com/TeamSPoon/with_thread_local.git
1.1.1177143ed10bf0b0d5448938d2fb7bba6bb105825ee1https://github.com/TeamSPoon/with_thread_local.git
1.1.118c738a6e9150a5dcdb55504f394be0c87e0fcb3a71https://github.com/TeamSPoon/with_thread_local.git
1.2.111bbd79be97d825166be4bca426598594a7cf0a8ff5https://github.com/TeamSPoon/with_thread_local.git
d8733f5fd197869468497bbfdd97df36c63dd5326https://github.com/TeamSPoon/with_thread_local.git

with_thread_local

Call a Goal with local assertions

Installation using SWI-Prolog 7.1 or later:

`?- pack_install('https://github.com/TeamSPoon/with_thread_local.git'). `

Source code available and pull requests accepted at http://github.com/logicmoo/with_thread_local

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)).

Some TODOs

Document this pack!

Write tests

Untangle the 'pack' install deps (Moving predicates over here from logicmoo_base)

Not obligated to maintain a git fork just to contribute

Dislike having tons of forks that are several commits behind the main git repo?

Be old school - Please ask to be added to TeamSPoon and Contribute directly !

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

BSD 2-Clause License

Copyright (c) 2017, TeamSPoon and Douglas Miles <logicmoo@gmail.com> All rights reserved.

Contents of pack "with_thread_local"

Pack contains 5 files holding a total of 4.2K bytes.