Call on determinate
Author(s): Jose F. Morales, Manuel Carro.Offers an enriched variant of call and cut !!/0 which executes pending goals when the computation has no more alternatives.
This library is useful to, for example, get rid of external connections once the necessary data has been obtained.
Usage and interface
- Library usage:
:- use_module(library(det_hook_rt)).
in which case, !!/0 is not available.Typically, this library is used as a package:
:- use_package(det_hook).
- New operators defined:
?/1 [200,fy], @/1 [200,fy]. - New modes defined:
+/1, -/1, ?/1, @/1, +/2, -/2, ?/2, @/2. - Imports:
- System library modules:
det_hook/det_hook_rt. - Packages:
prelude, nonpure, assertions, isomodes.
- System library modules:
Documentation on new modes
MODE
+/1:
(True) Usage:+A
- The following properties are added at call time:
(term_typing:nonvar/1)A is currently a term which is not a free variable.
MODE
-/1:
(True) Usage:-A
- The following properties are added at call time:
(term_typing:var/1)A is a free variable.
MODE
?/1:
MODE
@/1:
(True) Usage:@A
- The following properties are added globally:
(basic_props:not_further_inst/2)A is not further instantiated.
MODE
+/2:
(True) Usage:A+X
- The following properties are added at call time:
(undefined property)undefined:call(X,A)
MODE
-/2:
(True) Usage:A-X
- The following properties are added at call time:
(term_typing:var/1)A is a free variable. - The following properties are added upon exit:
(undefined property)undefined:call(X,A)
MODE
?/2:
(True) Usage:A?X
- Call and exit are compatible with:
(undefined property)undefined:call(X,A) - The following properties are added upon exit:
(undefined property)undefined:call(X,A)
MODE
@/2:
(True) Usage:@(A,X)
- The following properties are added at call time:
(undefined property)undefined:call(X,A) - The following properties are added upon exit:
(undefined property)undefined:call(X,A) - The following properties are added globally:
(basic_props:not_further_inst/2)A is not further instantiated.
Other information
As an example, the program:- module(_, _, [det_hook]). enumerate(X):- display(enumerating), nl, OnCut = (display('goal cut'), nl), OnFail = (display('goal failed'), nl), det_try(enum(X), OnCut, OnFail). enum(1). enum(2). enum(3).
behaves as follows:
?- enumerate(X). enumerating X = 1 ? ; X = 2 ? ; X = 3 ? ; goal failed
(note the message inserted on failure). The execution can be cut as follows:
?- use_package(det_hook). {Including /home/clip/lib/ciao/ciao-1.7/library/det_hook/det_hook.pl } yes ?- enumerate(X), '!!'. enumerating goal cut X = 1 ? ; no
Known bugs and planned improvements
- If the started goals do not exhaust their solutions, and '!!'/0 is not used, the database will populate with facts which will be consulted the next time a '!!'/0 is used. This could cause incorrect executions.