Author(s): José Morales, Manuel Carro.
Version: 1.7#149 (2001/11/19, 19:17:51 CET)
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.
det_hook_rt
)det_hook_rt
)
Meta-predicate with arguments: det_try(goal,goal,goal)
.
Usage: det_try(Goal, OnCut, OnFail)
Action
is called, and OnCut
and OnFail
are goals to be executed when Goal
is cut or when it finitely fails, respectively. In order for this to work, cutting must be performed in a special way, by using the
!!/0
predicate, also provided by this module.
Goal
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
OnCut
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
OnFail
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
det_hook_rt
)Usage:
OnCut
for any call in the scope of the cut.
det_hook_rt
)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
det_hook_rt
)Go to the first, previous, next, last section, table of contents.