head 1.133; access; symbols; locks ulrich:1.133; strict; comment @# @; 1.133 date 2023.04.15.07.37.28; author ulrich; state Exp; branches; next 1.132; 1.132 date 2023.04.15.06.48.24; author ulrich; state Exp; branches; next 1.131; 1.131 date 2011.09.21.09.31.44; author ulrich; state Exp; branches; next 1.130; 1.130 date 2011.09.21.08.42.38; author ulrich; state Exp; branches; next 1.129; 1.129 date 2011.09.19.12.43.42; author ulrich; state Exp; branches; next 1.128; 1.128 date 2011.07.20.21.55.50; author ulrich; state Exp; branches; next 1.127; 1.127 date 2011.07.20.21.53.15; author ulrich; state Exp; branches; next 1.126; 1.126 date 2010.07.19.18.41.45; author ulrich; state Exp; branches; next 1.125; 1.125 date 2010.06.29.14.43.06; author ulrich; state Exp; branches; next 1.124; 1.124 date 2010.06.29.14.38.21; author ulrich; state Exp; branches; next 1.123; 1.123 date 2010.06.24.01.55.24; author ulrich; state Exp; branches; next 1.122; 1.122 date 2009.12.16.20.08.58; author ulrich; state Exp; branches; next 1.121; 1.121 date 2009.12.16.19.35.54; author ulrich; state Exp; branches; next 1.120; 1.120 date 2009.12.07.23.05.00; author ulrich; state Exp; branches; next 1.119; 1.119 date 2009.12.07.14.00.22; author ulrich; state Exp; branches; next 1.118; 1.118 date 2009.12.07.13.52.21; author ulrich; state Exp; branches; next 1.117; 1.117 date 2009.12.07.02.40.07; author ulrich; state Exp; branches; next 1.116; 1.116 date 2009.12.06.00.07.36; author ulrich; state Exp; branches; next 1.115; 1.115 date 2009.12.04.00.49.52; author ulrich; state Exp; branches; next 1.114; 1.114 date 2009.12.03.06.31.51; author ulrich; state Exp; branches; next 1.113; 1.113 date 2009.12.03.05.57.45; author ulrich; state Exp; branches; next 1.112; 1.112 date 2009.12.03.05.56.42; author ulrich; state Exp; branches; next 1.111; 1.111 date 2009.11.30.03.27.46; author ulrich; state Exp; branches; next 1.110; 1.110 date 2009.11.28.23.36.50; author ulrich; state Exp; branches; next 1.109; 1.109 date 2009.11.28.23.27.13; author ulrich; state Exp; branches; next 1.108; 1.108 date 2009.11.28.21.28.09; author ulrich; state Exp; branches; next 1.107; 1.107 date 2009.11.13.15.08.46; author ulrich; state Exp; branches; next 1.106; 1.106 date 2009.11.13.15.05.23; author ulrich; state Exp; branches; next 1.105; 1.105 date 2009.11.13.15.04.45; author ulrich; state Exp; branches; next 1.104; 1.104 date 2009.11.13.14.19.57; author ulrich; state Exp; branches; next 1.103; 1.103 date 2009.11.13.13.48.22; author ulrich; state Exp; branches; next 1.102; 1.102 date 2009.11.13.12.12.31; author ulrich; state Exp; branches; next 1.101; 1.101 date 2009.11.10.01.17.21; author ulrich; state Exp; branches; next 1.100; 1.100 date 2009.10.29.00.53.48; author ulrich; state Exp; branches; next 1.99; 1.99 date 2009.10.29.00.45.40; author ulrich; state Exp; branches; next 1.98; 1.98 date 2009.10.29.00.45.00; author ulrich; state Exp; branches; next 1.97; 1.97 date 2009.10.29.00.43.46; author ulrich; state Exp; branches; next 1.96; 1.96 date 2009.10.19.17.14.49; author ulrich; state Exp; branches; next 1.95; 1.95 date 2009.10.17.23.14.19; author ulrich; state Exp; branches; next 1.94; 1.94 date 2009.10.17.23.09.16; author ulrich; state Exp; branches; next 1.93; 1.93 date 2009.10.07.12.03.47; author ulrich; state Exp; branches; next 1.92; 1.92 date 2009.10.07.11.58.25; author ulrich; state Exp; branches; next 1.91; 1.91 date 2009.10.04.20.23.39; author ulrich; state Exp; branches; next 1.90; 1.90 date 2009.10.04.15.27.42; author ulrich; state Exp; branches; next 1.89; 1.89 date 2009.09.29.16.34.09; author ulrich; state Exp; branches; next 1.88; 1.88 date 2009.09.29.15.12.23; author ulrich; state Exp; branches; next 1.87; 1.87 date 2009.09.29.11.17.24; author ulrich; state Exp; branches; next 1.86; 1.86 date 2009.09.29.11.11.37; author ulrich; state Exp; branches; next 1.85; 1.85 date 2009.09.29.10.46.35; author ulrich; state Exp; branches; next 1.84; 1.84 date 2009.09.29.10.32.25; author ulrich; state Exp; branches; next 1.83; 1.83 date 2009.09.29.10.29.29; author ulrich; state Exp; branches; next 1.82; 1.82 date 2009.09.29.01.01.57; author ulrich; state Exp; branches; next 1.81; 1.81 date 2009.09.28.23.11.18; author ulrich; state Exp; branches; next 1.80; 1.80 date 2009.09.24.20.41.10; author ulrich; state Exp; branches; next 1.79; 1.79 date 2009.09.24.20.31.04; author ulrich; state Exp; branches; next 1.78; 1.78 date 2009.09.11.15.35.04; author ulrich; state Exp; branches; next 1.77; 1.77 date 2009.09.05.22.33.24; author uwn; state Exp; branches; next 1.76; 1.76 date 2009.09.05.22.29.24; author uwn; state Exp; branches; next 1.75; 1.75 date 2009.09.05.22.28.40; author uwn; state Exp; branches; next 1.74; 1.74 date 2009.09.01.22.14.10; author uwn; state Exp; branches; next 1.73; 1.73 date 2009.09.01.18.56.53; author uwn; state Exp; branches; next 1.72; 1.72 date 2009.09.01.17.28.58; author uwn; state Exp; branches; next 1.71; 1.71 date 2009.09.01.12.53.41; author uwn; state Exp; branches; next 1.70; 1.70 date 2009.09.01.12.48.01; author uwn; state Exp; branches; next 1.69; 1.69 date 2009.09.01.12.16.45; author uwn; state Exp; branches; next 1.68; 1.68 date 2009.09.01.12.16.21; author uwn; state Exp; branches; next 1.67; 1.67 date 2009.09.01.12.15.46; author uwn; state Exp; branches; next 1.66; 1.66 date 2009.08.31.23.48.38; author uwn; state Exp; branches; next 1.65; 1.65 date 2009.08.31.22.39.53; author uwn; state Exp; branches; next 1.64; 1.64 date 2009.08.29.08.37.16; author uwn; state Exp; branches; next 1.63; 1.63 date 2009.08.29.05.44.27; author uwn; state Exp; branches; next 1.62; 1.62 date 2009.08.28.16.21.10; author uwn; state Exp; branches; next 1.61; 1.61 date 2009.08.28.14.16.57; author ulrich; state Exp; branches; next 1.60; 1.60 date 2009.08.25.10.30.05; author ulrich; state Exp; branches; next 1.59; 1.59 date 2009.08.24.09.42.57; author ulrich; state Exp; branches; next 1.58; 1.58 date 2009.08.24.09.40.18; author ulrich; state Exp; branches; next 1.57; 1.57 date 2009.08.24.09.09.27; author ulrich; state Exp; branches; next 1.56; 1.56 date 2009.08.24.08.49.31; author ulrich; state Exp; branches; next 1.55; 1.55 date 2009.08.22.02.35.32; author ulrich; state Exp; branches; next 1.54; 1.54 date 2009.08.22.02.16.41; author ulrich; state Exp; branches; next 1.53; 1.53 date 2009.08.19.16.22.10; author ulrich; state Exp; branches; next 1.52; 1.52 date 2009.08.19.12.34.17; author ulrich; state Exp; branches; next 1.51; 1.51 date 2009.08.18.19.18.55; author ulrich; state Exp; branches; next 1.50; 1.50 date 2009.08.18.17.41.26; author ulrich; state Exp; branches; next 1.49; 1.49 date 2009.08.18.17.28.30; author ulrich; state Exp; branches; next 1.48; 1.48 date 2009.08.18.15.52.18; author ulrich; state Exp; branches; next 1.47; 1.47 date 2009.08.18.15.31.46; author ulrich; state Exp; branches; next 1.46; 1.46 date 2009.08.18.15.30.01; author ulrich; state Exp; branches; next 1.45; 1.45 date 2009.08.14.01.19.56; author ulrich; state Exp; branches; next 1.44; 1.44 date 2009.08.14.01.01.03; author ulrich; state Exp; branches; next 1.43; 1.43 date 2009.08.14.00.37.59; author ulrich; state Exp; branches; next 1.42; 1.42 date 2009.08.13.16.39.07; author ulrich; state Exp; branches; next 1.41; 1.41 date 2009.08.13.16.35.40; author ulrich; state Exp; branches; next 1.40; 1.40 date 2009.08.13.16.29.05; author ulrich; state Exp; branches; next 1.39; 1.39 date 2009.08.13.16.10.58; author ulrich; state Exp; branches; next 1.38; 1.38 date 2009.08.12.17.28.36; author ulrich; state Exp; branches; next 1.37; 1.37 date 2009.08.12.17.19.31; author ulrich; state Exp; branches; next 1.36; 1.36 date 2009.08.11.19.12.41; author ulrich; state Exp; branches; next 1.35; 1.35 date 2009.08.11.19.11.57; author ulrich; state Exp; branches; next 1.34; 1.34 date 2009.08.11.18.37.11; author ulrich; state Exp; branches; next 1.33; 1.33 date 2009.08.11.18.34.56; author ulrich; state Exp; branches; next 1.32; 1.32 date 2009.08.11.12.33.12; author ulrich; state Exp; branches; next 1.31; 1.31 date 2009.08.04.18.52.45; author ulrich; state Exp; branches; next 1.30; 1.30 date 2009.08.04.18.40.44; author ulrich; state Exp; branches; next 1.29; 1.29 date 2009.08.04.17.57.33; author ulrich; state Exp; branches; next 1.28; 1.28 date 2009.08.03.12.36.51; author ulrich; state Exp; branches; next 1.27; 1.27 date 2009.08.03.11.04.10; author ulrich; state Exp; branches; next 1.26; 1.26 date 2009.07.30.17.05.10; author ulrich; state Exp; branches; next 1.25; 1.25 date 2009.07.21.10.17.23; author ulrich; state Exp; branches; next 1.24; 1.24 date 2009.07.02.23.57.48; author ulrich; state Exp; branches; next 1.23; 1.23 date 2009.07.02.22.22.45; author ulrich; state Exp; branches; next 1.22; 1.22 date 2009.07.02.19.40.51; author ulrich; state Exp; branches; next 1.21; 1.21 date 2009.07.02.19.38.09; author ulrich; state Exp; branches; next 1.20; 1.20 date 2009.07.02.18.02.21; author ulrich; state Exp; branches; next 1.19; 1.19 date 2009.07.02.17.23.03; author ulrich; state Exp; branches; next 1.18; 1.18 date 2009.07.02.17.22.24; author ulrich; state Exp; branches; next 1.17; 1.17 date 2009.07.02.17.13.34; author ulrich; state Exp; branches; next 1.16; 1.16 date 2009.07.02.17.12.21; author ulrich; state Exp; branches; next 1.15; 1.15 date 2009.07.02.16.57.35; author ulrich; state Exp; branches; next 1.14; 1.14 date 2009.07.02.16.03.00; author ulrich; state Exp; branches; next 1.13; 1.13 date 2009.07.02.14.56.19; author ulrich; state Exp; branches; next 1.12; 1.12 date 2009.07.02.14.50.03; author ulrich; state Exp; branches; next 1.11; 1.11 date 2009.07.02.14.28.23; author ulrich; state Exp; branches; next 1.10; 1.10 date 2009.07.02.14.11.51; author ulrich; state Exp; branches; next 1.9; 1.9 date 2009.07.02.13.45.20; author ulrich; state Exp; branches; next 1.8; 1.8 date 2009.07.02.12.28.30; author ulrich; state Exp; branches; next 1.7; 1.7 date 2009.07.02.03.22.29; author ulrich; state Exp; branches; next 1.6; 1.6 date 2009.07.02.03.19.27; author ulrich; state Exp; branches; next 1.5; 1.5 date 2009.07.02.03.04.43; author ulrich; state Exp; branches; next 1.4; 1.4 date 2009.07.02.02.56.30; author ulrich; state Exp; branches; next 1.3; 1.3 date 2009.07.02.02.56.04; author ulrich; state Exp; branches; next 1.2; 1.2 date 2009.07.02.02.54.19; author ulrich; state Exp; branches; next 1.1; 1.1 date 2009.07.02.02.43.55; author ulrich; state Exp; branches; next ; desc @@ 1.133 log @correction @ text @
NOTE — A built-in predicatecall_cleanup/2
with similar functionality is implemented in many existing processors. It is often used to free temporary resources. In the presence of interrupts (7.12 note c),call_cleanup/2
can cause leakage of resources: A processor receiving interrupts between resource allocation andcall_cleanup/2
is unable to free the resource in a timely manner. To overcome this problem,setup_call_cleanup/3
protects resource allocation from interrupts.
setup_call_cleanup(S, G, C)
is true
iff once(S), call(G)
is true.
Procedurally, the control construct shall be executed as follows:
once(S)
is executed while being protected from interrupts:
once(S)
is executed
entirely and the cleanup handler C
is installed
upon success;
once(S)
is interrupted by an
implementation
dependent interrupt (7.12 note c). In this case, once(S)
does not leave an
observable
effect.
call(G)
is called.
G
. Earlier moments are:
G
is true or false, C
is
called at an implementation dependent moment after the last
solution and after the last observable effect of G
.
G
or the continuation of G
is interrupted by a call of throw/1
(7.8.9 a,
b), whose corresponding call of catch/3
is above G
.C
, throw/1
continues to search the corresponding call of catch/3
,
regardless of the outcome of C
.
Thus, if C
is interrupted by another call of
throw/1
, that throw/1
is lost.
G
executes a cut
explicitly or implicitly that is associated with the cutparent of G
(7.7.2, 7.8.4.1 Note 1b).C
is called in
the place of the cut.
A cut is performed implicitly for (->)/2
- if-then
(7.8.7), (;)/2
- if-then-else (7.8.8), (\+)/1
(8.15.1), once/1
(8.15.2).
C
is called as once(C)
. Failure
of C
is ignored. An explicit or
implicit throw/1
is ignored in case 7.8.11.1 c2;
otherwise (case 7.8.11.1 c1 or
7.8.11.1 c3), it is passed towards the corresponding call of catch/3
.
C
shares bindings and variables
with S
, with G
and with the continuation. The
bindings up to and including S
are always present. No further bindings
are present when C
is executed at 7.8.11.1 c2 and at the
latest moment of 7.8.11.1 c1. At 7.8.11.1 c2, and at the
earliest moment of 7.8.11.1 c1, all bindings are present at the time of calling
the cut. All other cases of 7.8.11.1 c1 are implementation dependent.
A processor may restrict execution of C
in an
implementation defined manner. For example, a processor may restrict the
handling of interrupts within C
or limit resource
consumption.
NOTES
1
Existing processors locate c1 either when the last solution is found,
or upon failure.
The precise moment is implementation dependent due to the
varying ability of Prolog processors to detect determinism. For
example, a processor may execute call((call(G);fail))
as call(G)
and vice versa.
2
For nonterminating goals like repeat
(8.15.3) only c2 and
c3 can trigger the cleanup. And if a nonterminating goal does not find a
solution, only c2 can trigger.
3
A throw/1
of G
has priority over one
of C
(7.8.11.1 c2). This is an advantage when recovering
errors, like resource errors (7.12.2 h), where the error
of C
is often a consequence of the error
of G
.
setup_call_cleanup(goal, goal, goal)
NOTE — The arguments should eventually be
+callable_term
. However, neither type nor mode is
checked when this control construct is executed (8.1.2.2).
S
is a callable term that is not permitted due
to an implementation defined restrictionrepresentation_error(setup_goal)
.
S
finds a solution, but C
is
a variableinstantiation_error
. Goal G
is not executed.
S
finds a solution, but C
is
neither a variable nor a callable termtype_error(callable, C)
. Goal G
is not executed.
NOTE — Further errors inS
andG
may happen due to callingonce/1
orcall/1
(see 7.8.11.1).
write/1
uses the standard operator table
(6.3.4.4, table 7). Unique variables are written
as _
which is one possible way to
realize 7.10.5 a. The different outcomes (labeled either/or) are due to the
implementation dependence in c1.
setup_call_cleanup(fail, _, _). Fails. Neither the goal nor the cleanup is executed. setup_call_cleanup(throw(ex), _, _). System error due to uncaught ex. setup_call_cleanup(true, throw(unthrown),_). Instantiation error. setup_call_cleanup(true, true, ( true ; throw(x) )). Succeeds. No system error. setup_call_cleanup(true, X = 1, X = 2). Succeeds, unifying X = 1. setup_call_cleanup(true, true, X = 2). Either: Succeeds, unifying X = 2. Or: Succeeds. setup_call_cleanup(true, X=true,X). Instantiation error. setup_call_cleanup(X=throw(ex), true, X). Either: System error due to uncaught ex. Or: Succeeds. System error on backtracking. setup_call_cleanup(true, true, fail). Succeeds. setup_call_cleanup(S=1, G=2, C=3). Either: Succeeds, unifying S = 1, G = 2, C = 3. Or: Succeeds, unifying S = 1, G = 2. setup_call_cleanup((S=1;S=2), G=3, C=4). Either: Succeeds, unifying S = 1, G = 3, C = 4. Or: Succeeds, unifying S = 1, G = 3. setup_call_cleanup(S=1,G=2,write(S+G)). Succeeds, unifying S = 1, G = 2. Either: outputs '1+2' Or: outputs on backtracking '1+_' prior to failure. Or (?): outputs on backtracking '1+2' prior to failure. setup_call_cleanup(S=1,(G=2;G=3),write(S+G)). Succeeds, unifying S = 1, G = 2. On backtracking, succeeds unifying S = 1 and G = 3. Either: outputs '1+3' Or: on backtracking outputs '1+_' prior to failing Or (?): on backtracking outputs '1+3' prior to failing. setup_call_cleanup(S=1,G=2,write(S+G>A+B)), A=3, B=4. Succeeds, unifying S=1,G=2,A=3,B=4. Either: Outputs one of the following before succeeding 1+2>_+_. 1+2>3+_. 1+2>3+4. Disputable: 1+2>_+4. Or: outputs one of the above outputs on backtracking prior to failing. setup_call_cleanup(S=1,(G=2;G=3,throw(x)),write(S+G)). Succeeds, unifying S = 1, G = 2. On backtracking, outputs '1+_' prior to system error due to uncaught x. setup_call_cleanup(open(f,read,S),read(S,X),close(S)). Opens file f for reading, reads a term and closes the file. Succeeds, unifying S with an implementation dependent stream term, unifying X with the term read. The file is closed, either immediately, or on backtracking, and even if there is an error in read.
setup_call_cleanup(S=1,(G=2;G=3),write(S+G>B)), B=4, !. Outputs '1+2>4'. Succeeds, unifying S = 1, G = 2, B = 4. setup_call_cleanup(S=1,G=2,write(S+G>B)),B=3,!. Either: Outputs '1+2>_'. Succeeds, unifying S = 1, G = 2, B = 3. Or: Outputs '1+2>3'. Succeeds, unifying S = 1, G = 2, B = 3. setup_call_cleanup(S=1,(G=2;fail),write(S+G>B)), B=3, !. Same as above. setup_call_cleanup(S=1,(G=2;S=2),write(S+G>B)), B=3, !. Same as above. setup_call_cleanup(S=1,(G=2;G=3), write(S+G>B)), B=4, throw(x). Outputs '1+_>_'. system_error due to uncaught x. setup_call_cleanup(S=1,(G=2;G=3), write(S+G>B)), B=4, !, throw(x). Outputs '1+2>4'. system_error due to uncaught x. setup_call_cleanup(true, (X=1;X=2), write(a)), setup_call_cleanup(true,(Y=1;Y=2),write(b)), throw(x). Outputs 'ba'. system_error due to uncaught x. setup_call_cleanup(true, (X=1;X=2), write(a)), setup_call_cleanup(true,(Y=1;Y=2),write(b)), !. Outputs 'ba'. Succeeds, unifying X = 1, Y = 1.
catch(setup_call_cleanup(true,throw(goal),throw(cl)), Pat, true). Succeeds unifying Pat = goal. catch(( setup_call_cleanup(true,(G=1;G=2),throw(cl)), throw(cont)), Pat, true). Succeeds unifying Pat = cont. catch( setup_call_cleanup(true, throw(a), setup_call_cleanup(true,fail,throw(b)) ), Pat, true). Succeeds unifying Pat with a.
setup_call_cleanup(S, G, C) :- once(S), call_cleanup(G, C).
catch/3
.
d369 7
@
1.127
log
@?term to goal. Actually happend 2010-07-24 14:58:38
already.
@
text
@d244 3
a246 2
NOTE — Further errors in S
and G
are already implied by 7.8.11.1.
@
1.126
log
@*** empty log message ***
@
text
@d214 1
a214 1
setup_call_cleanup(?term, ?term, ?term)
@
1.125
log
@Consistent variable names
@
text
@d397 1
a397 1
S,
d404 2
d409 1
a409 1
once(S)
does not leave an
d122 1
a122 1
effect
@
1.118
log
@a1
@
text
@d120 1
a120 1
dependent interrupt (7.12 note c) without leaving an
d122 1
a122 1
effect.
@
1.117
log
@Problematic case
@
text
@d118 1
a118 1
setup_call_cleanup/3
is interrupted by an
@
1.116
log
@*** empty log message ***
@
text
@d120 1
a120 1
dependent interrupt (7.12 note c) without leaving an
d122 1
a122 1
effect.
@
1.115
log
@Vitor's example
@
text
@d153 1
a153 1
After the cut has been executed, C
is called in
d244 2
a245 2
NOTE — Further errors due to S
and G
are already implied by the present definition.
d262 1
a262 1
setup_call_cleanup(throw(ex),true,true).
@
1.114
log
@ECLiPSe status
@
text
@d60 1
a60 1
2009-12-03
d80 1
d257 1
d262 3
d375 1
a375 1
throw/1
is ignored for c2; otherwise (c1 or
c3), it is passed to the corresponding call of catch/3
.
d180 4
a183 3
are present when C
is executed at c2 and at the latest moment of c1. At c2, and at the
earliest moment of c1, all bindings are present at the time of calling
the cut. All other cases of c1 are implementation dependent.
d213 1
a213 1
of C
(c2). This is an advantage when recovering
@
1.99
log
@post
@
text
@d71 3
a73 1
of N208 2008-11-17. Earlier version: N211 2009-07-02.
d107 1
a107 1
iff once(S), call(G)
is true.
@
1.98
log
@N215 final
@
text
@d7 1
a7 1
throw/1
explicitly or implicitly (7.8.9 a,
d152 2
a153 2
Thus, if C
executes another
relevant throw/1
, that throw/1
is lost.
@
1.93
log
@Removed errors for S.
They are implicitely defined by calling once(S)
@
text
@d71 1
a71 1
13211-1:2006 of 2008-11-17.
d221 1
a221 1
NOTE — The second and third argument should eventually be
d223 1
a223 1
checked when the control construct is executed (8.1.2.2).
d247 2
a248 2
NOTE — Errors due to S
and G
are
already implied by the present definition.
a251 1
@
1.92
log
@Shorter Note
@
text
@d217 1
a217 1
setup_call_cleanup(+callable_term, ?term, ?term)
d228 1
d231 1
a231 8
S
is a variableinstantiation_error
.
S
is neither a variable nor a callable
termtype_error(callable, S)
.
S
is a callable term that is not permitted due
d235 1
a235 1
S
finds a solution, but C
is
d239 1
a239 1
S
finds a solution, but C
is
d247 2
a248 2
NOTE — Errors due to G
are already implied by the
present definition.
d372 1
a372 1
C
is installed, but G
is a
variableinstantiation_error
. Cleanup C
is executed.
C
is installed, but G
is
neither a variable nor a callable termtype_error(callable, G)
. Cleanup C
is
executed.
setup_call_cleanup(+callable_term, ?callable_term, ?callable_term)
d249 10
a258 2
C
is installed, but G
is a variableG
. Earlier moments are:
@
1.69
log
@c version 2
@
text
@d134 1
a134 1
G
is true or false, C
will be
@
1.68
log
@c version 1
@
text
@d127 2
a128 3
G
. Earlier
moments are:
@
1.67
log
@c improvements & notes
@
text
@d127 2
a128 2
G
. Earlier
@
1.66
log
@c1
@
text
@d127 3
a129 3
C
shall be
the failure over G
.
d131 1
a131 1
C
, the "ball"
of throw/1
will be passed, regardless of the
outcome of C
.
d193 2
d198 11
a208 5
There are several advantages for giving priority to
the throw/1
of G
in c2 in the context of
error recovery. The error of C
is often a consequence of
the error of G
. This is particularly true for resource
errors (7.12.2 h).
@
1.65
log
@First attempt to simplify c1.
@
text
@d135 3
a137 7
G
is true, C
will be called at an
implementation dependent moment
after the last solution of G
is found; and
after the last observable effect of G
.
@
1.64
log
@m
@
text
@d107 1
a107 1
once(S)
is executed while being protected from interrupts:
d109 1
d124 2
a125 2
call(G)
is called.
d127 5
a131 3
G
has completed
execution. It is called exactly once at one of the following moments:
d135 2
a136 10
G
has completed execution by success or failure.
The precise moment is implementation dependent
within the interval defined by the following bounds:
G
is found, if
G
is true;
d138 1
a138 1
G
, if applicable;
d140 1
a140 1
G
.
a141 1
When several cleanup goals are triggered simultaneously, the goals
@
1.63
log
@Reorder Notes to the end of clause 7.8.11.1. This corresponds to the
convention of 13211-1:1995.
@
text
@d150 1
a150 1
executes a throw/1
(explicitly or implicitly — 7.8.9 a or
d160 1
a160 1
(explicitly or implicitly) that is associated with the cutparent of G
d196 1
a196 1
1 d203 1 a203 1
2 @ 1.62 log @First change on gupu2 @ text @a148 6
NOTE — The precise moment is implementation dependent due to
the varying ability of Prolog processors to detect determinism.
For example, a processor may execute
call((call(G);fail))
as call(G)
and vice versa.
d156 2
a157 15
NOTES
C
executes another
relevant throw/1
, that throw/1
is
lost.
throw/1
of G
in the context of
error recovery. The error of C
is often a
consequence of the error of G
. This is
particularly true for resource errors (7.12.2 h).
call(G)
is called.
d138 1
a138 1
setup_call_cleanup/3
protects a
goal for setup in a separate argument.
d132 1
a132 1
G
has completed execution normally.call((call(G);fail))
a188 3
When several cleanup goals are triggered simltaneously, the goals
are executed in reversed order of their installation.
d193 4
a196 1
c3), it is passed to the next matching catch/3
.
d205 1
d325 2
a326 3
The file is closed, either immediately or on backtracking.
In any case, even if there is an error in read, the
file will be closed.
d386 2
a387 2
setup_call_cleanup(Setup, Goal, Cleanup)
is true
iff once(Setup), call(Goal)
is true.
d103 1
a103 1
it
d107 1
a107 1
once(Setup)
is executed while being protected from interrupts:
d111 2
a112 2
once(Setup)
is executed
entirely and the cleanup handler Cleanup
is installed
d124 1
a124 1
After the cleanup handler is installed, call(Goal)
is called.
d127 1
a127 1
The cleanup handler is called after Goal
has completed
d132 1
a132 1
Goal
has completed execution normally.Goal
is found, if
Goal
is true;
d143 1
a143 1
Goal
, if applicable;
d145 1
a145 1
Goal
.
d152 2
a153 2
goal call((call(Goal);fail))
as call(Goal)
and vice versa.
d155 1
a155 1
Goal
or the continuation of Goal
d157 2
a158 2
b), whose corresponding call of catch/3
is above Goal
.Cleanup
, the "ball"
d160 1
a160 1
outcome of Cleanup
.
d166 1
a166 1
Cleanup
executes another
d171 3
a173 3
the throw/1
of Goal
in the context of
error recovery. The error of Cleanup
is often a
consequence of the error of Goal
. This is
d178 2
a179 2
Goal
executes a cut
(explicitly or implicitly) that is associated with the cutparent of Goal
d181 1
a181 1
After the cut has been executed, Cleanup
is called in
d193 2
a194 2
Cleanup
is called as once(Cleanup)
. Failure
of Cleanup
is ignored. An explicit or
d198 4
a201 4
Cleanup
shares bindings and variables
with Setup
, with Goal
and with the continuation. The
bindings up to and including Setup
are always present. No further bindings
are present when Cleanup
is executed at c2 and at the latest moment of c1. At c2, and at the
d205 1
a205 1
A processor may restrict execution of Cleanup
in an
d207 1
a207 1
handling of interrupts within Cleanup
or limit resource
d219 1
a219 1
Setup
is a variableSetup
is neither a variable nor a callable
d224 1
a224 1
type_error(callable,Setup)
.
d226 1
a226 1
Setup
is a callable term that is not permitted due
d230 1
a230 1
Setup
finds a solution, but Cleanup
is
d232 1
a232 1
instantiation_error
. Goal
is not executed.
d234 1
a234 1
Setup
finds a solution, but Cleanup
is
d236 1
a236 1
type_error(callable, Cleanup)
. Goal
is not executed.
d238 1
a238 1
Cleanup
is installed, but Goal
d240 1
a240 1
instantiation_error
. The Cleanup
is executed.
d242 1
a242 1
Cleanup
is installed, but Goal
is
d244 1
a244 1
type_error(callable, Goal)
. The Cleanup
is
d260 1
a260 1
Fails. Neither Goal nor Cleanup is executed.
d371 2
a372 2
call_cleanup/2
is
implemented in many existing processors to provide similar
functionality as setup_call_cleanup/3
. It is often used
d96 1
a96 1
goal in a separate argument.
d102 3
d124 1
a124 2
After the cleanup handler is installed, the Goal
is called as
in call(Goal)
with the cleanup handler present.
d127 2
a128 1
The cleanup handler is called exactly once at one of the following moments:
a177 4
When several Cleanup
goals are triggered, the
goals are executed in reversed order of their installation.
d179 1
a179 1
(explicitly or implicitly) that is associated with the cutparent of Goal
d186 2
d189 2
a190 6
When a cut will trigger several Cleanup
goals, the
order in which those goals are executed is implementation
dependent.
d206 1
a206 1
implementation dependent manner. For example, a processor may restrict the
d230 9
a238 1
Setup
finds a solution, but Goal
d242 1
a242 1
Setup
finds a solution, but Goal
is
a246 8
Setup
finds a solution, but Cleanup
is
a variableinstantiation_error
. Goal
is not executed.
Setup
finds a solution, but Cleanup
is
neither a variable nor a callable termtyp_error(callable, Cleanup)
. Goal
is not executed.
a349 1
a350 2
d352 1 a352 2 Either: Outputs 'ab'. Succeeds, unifying X = 1, Y = 1. Or: Outputs 'ba'. Succeeds, unifying X = 1, Y = 1. d382 1 a382 1 for unbound Cleanup, once for Setup due to Pasadena resolution @ 1.54 log @Changes of Feliks Kluzniak Mail Fri, 21 Aug 2009 19:48:37 -0500 @ text @d138 1 a138 1 there are solutions; @ 1.53 log @*** empty log message *** @ text @d135 1 a135 1
Goal
;
d137 2
a138 1
Goal
is found, if applicable;
@
1.52
log
@Corrected 7.8.11.3 g, minor
@
text
@d203 1
a203 1
are present when Cleanup
is executed at c2 and at the latest moment of c1. At c2, and at the
@
1.51
log
@*** empty log message ***
@
text
@d67 1
a67 1
2009-08-18
d73 1
a73 1
References refer to 13211-1:1995. Parts needing improvements are underlined
d100 1
a100 2
iff once(Setup), call(Goal)
is true,
and Cleanup
is not replaced by throw/1
.
d115 1
d175 1
a175 1
younger goals is executed first.
d234 1
a234 1
instantiation_error
. The Cleanup
is still executed.
d239 1
a239 1
still executed.
d247 1
a247 1
instantiation_error
. Goal
is not executed.
d257 1
a257 3
realize 7.10.5 a)
The different outcomes (labeled either/or) are due to the
d275 1
a275 1
Or: Succeeds. Fails on backtracking
d289 1
a289 2
Or: Succeeds, unifying S = 1, G = 2. Fails
on backtracking.
d299 4
a302 4
Or: outputs on backtracking '1+_',
prior to failing.
Or (?): outputs on backtracking '1+2',
prior to failing.
@
1.50
log
@Better justification of c2
@
text
@d201 1
a201 1
with Setup
, with Goal
and with the continuation. The
@
1.49
log
@State order of Cleanup goals for c2 and c3
@
text
@d158 15
a172 2
NOTE — Thus, if Cleanup
executes
another relevant throw/1
, that throw/1
is lost.
@
1.48
log
@Multiple exception case clarified
@
text
@d161 4
d174 4
d342 7
@
1.47
log
@Better mode, as Setup may instantiate Goal and Cleanup
@
text
@d158 2
a159 3
NOTE — As a consequence, the "ball"
of Cleanup
is lost in case Cleanup
executes another throw/1
.
@
1.46
log
@Many comments from Feliks Kluzniak
Mail Fri, 14 Aug 2009 13:20:01 -0500
@
text
@d196 1
a196 1
setup_call_cleanup(+callable_term,+callable_term, +callable_term)
@
1.45
log
@*** empty log message ***
@
text
@d66 3
a68 1
call_cleanup/2
is unable to free the resource timely.
d105 1
a105 1
once(Setup)
is executed protected from interrupts.
d109 1
a109 1
once(Setup)
is executed
d111 1
a111 1
upon success.
d113 1
a113 1
setup_call_cleanup/3
is interrupted by an
d131 1
a131 1
within the interval defined by the following bounds.
d135 1
a135 1
Goal
d137 1
a137 1
Goal
, if applicable
d139 1
a139 1
Goal
, if applicable
d141 1
a141 1
Goal
d145 1
a145 1
NOTE — The implementation dependence is due to
d177 1
a177 1
implicit throw/1
is ignored for c2. Otherwise (c1 or
d181 3
a183 3
with Setup
, Goal
and the continuation. The
bindings of Setup
are always present. No further bindings
are present in c2 and at the latest moment of c1. In c2, and in the
d187 2
a188 2
A processor may restrict execution of Cleanup
in an
implementation dependent manner. E.g., a processor may restrict the
d201 1
a201 1
Setup
is a variable.Setup
, Goal
is a
variableSetup
, Goal
is
d221 1
a221 1
Setup
, Cleanup
is
d225 1
a225 1
Setup
, Cleanup
is
d234 2
a235 2
In the following, write/1
outputs using standard
operators (6.3.4.4, table 7). Unique variables are written
d237 1
a237 1
realize the implementation dependent manner of 7.10.5 a)
d373 1
@
1.44
log
@*** empty log message ***
@
text
@d214 1
a214 1
type_error(callable, Goal)
. The Cleanup
x is
@
1.43
log
@Better error formatting
@
text
@d1 1
a1 1
d66 1
a66 1
once(Setup)
is executed protected from interrupts.
d116 1
a116 1
setup_call_cleanup/3
protects goals in
a separate argument.
@
1.35
log
@Added link to WG17 Document register
@
text
@d55 1
a55 1
Cleanup
is not replaced by throw/1
.
@
1.28
log
@renumbering from 8.15.5 to 7.8.11
@
text
@d334 1
a334 1
exceptions from aside. Instantiation error for unbound Cleanup.
@
1.27
log
@Correction SWI status
@
text
@d62 1
a62 1
Cleanup
(Manual is correct though).
@
1.25
log
@Pasadena WG17 comments
@
text
@d51 1
a51 1
setup_call_cleanup/3
protects goals in
d81 1
a81 1
iff call(Setup), call(Goal)
is true,
d87 1
a87 1
Setup
is executed protected from interrupts.
d91 1
a91 1
Setup
is executed
d93 1
a93 1
for each solution of Setup
.
d103 1
a103 2
After the cleanup handler is installed for a solution
of Setup
, the Goal
is called as
d145 1
a145 1
(explicitly or implicitly) that concerns the cutparent of Goal.catch/3
is above Goal
.Goal
has completed execution normally.
d117 1
a117 1
catch/3
is above Goal
.
d145 3
a147 3
(explicitly or implicitly) that concerns the cutparent of Goal.
Cleanup
is called in the place of the cut, after the
cut has been executed.
d157 1
a157 2
When Cleanup
is called, it is called
as once(Cleanup)
. Failure
@
1.14
log
@*** empty log message ***
@
text
@d111 3
a113 3
NOTE —
The implementation dependence is due to the
varying abilities of Prolog processors to detect determinism. For example, a
particular processor may execute a goal call(call(Goal) ;
fail)
as call(Goal)
and vice versa.
d148 3
a150 2
A cut is performed implicitly for (->)/2 - if-then (7.8.7), (;)/2 -
if-then-else (7.8.8), (\+)/1 (8.15.1), once/1 (8.15.2).
@
1.13
log
@*** empty log message ***
@
text
@d86 1
a86 3
Setup
is executed, while being protected from implementation
dependent interrupts (7.12 note c). I.e. one of the following steps
are performed.
d91 2
a92 1
entirely and the cleanup handler Cleanup
is installed.
d94 3
a96 1
Setup
is interrupted without leaving an
d102 3
a104 2
After the cleanup handler is installed, the Goal
is
called as in call(Goal)
with the cleanup handler present.
d111 15
a125 5
Goal
and after the last observable effect of Goal
—
whichever comes last — and up to the failing
of Goal
. The precise moment is implementation
dependent and may thus be overshadowed by 2 or 3.
@
1.12
log
@*** empty log message ***
@
text
@d239 1
a239 1
Or: Succeeds, unifying S = 1, G = 2.
@
1.11
log
@*** empty log message ***
@
text
@d87 12
a98 4
dependent interrupts (7.12 note c). I.e., either Setup
is executed
entirely and a Cleanup
handler is installed. Or:
Setup
is interrupted prior to having performed an
observable effect.
d157 5
d203 1
a203 1
implementation dependent manner of being able to detect determinism.
@
1.10
log
@*** empty log message ***
@
text
@d71 1
a71 1
to free temporary resources. In the presence of interrupts (7.12 NOTE
d75 2
a76 2
For this reason, there is a separate argument for protected goals
in setup_call_cleanup/3
.
d81 1
a81 1
and Cleanup
did not execute a throw/1
.
d87 1
a87 1
dependent interrupts. I.e., either Setup
is executed
d101 3
a103 2
Goal
and after the last observable effect of Goal
and up to the failing
@
1.9
log
@*** empty log message ***
@
text
@d56 1
a56 1
Below, we are referring to 13211-1:1995.
d71 3
a73 3
to free temporary resources. In the presence of
interrupts, call_cleanup/2
can cause leakage of resources:
A processor receiving interrupts between resource allocation and
d75 2
a76 2
For this reason, setup_call_cleanup/3
takes goals to be
protected as a separate argument.
d79 3
a81 3
setup_call_cleanup(Setup, Goal, Cleanup)
is true
iff call(Setup), call(Goal)
is true, and Cleanup
did not
execute a throw/1
.
d86 5
a90 5
Setup
is executed, being protected from implementation
dependent interrupts (7.12 NOTE c). This means that either, Setup
is
interrupted prior to having performed some visible effect, or it is
executed entirely. The protection includes the installation of
a Cleanup
handler.
d108 1
a108 1
varying indexing abilities of Prolog processors. A
@
1.8
log
@Comments Markus Triska
@
text
@d81 1
a81 1
produce an exception.
d97 1
a97 1
The cleanup handler is called in one of the following situations:
d101 10
a110 3
Goal
and after the last
observable effect of Goal
and up to the failing
of Goal
. The precise moment is implementation dependent.
d114 1
a114 2
b), whose matching catch/3 is above Goal
,
Cleanup
is called as if Goal
fails.
d116 1
a116 1
of throw/1
is passed, regardless of the
d119 3
a121 2
Cleanup
executes
another throw/1
, the "ball" of Cleanup
is lost.
d125 2
d133 1
a133 9
The cleanup handler shares the bindings with Setup
and Goal
. (NOTE No copying takes place as
in throw/1
). When the cleanup is called, the bindings of
the setup are all present, whereas the bindings of goal depend on the
specific situation.
once(Cleanup)
. Success or
failure is always ignored.
d135 12
a146 25
throw/1
is passed on.
NOTES@ 1.7 log @*** empty log message *** @ text @d242 1 a242 1 Or: Succeeds, unifying S = 1, G = 2. @ 1.6 log @*** empty log message *** @ text @d134 4 @ 1.5 log @*** empty log message *** @ text @d80 1 a80 1 iff
- For each solution of
Setup
and thus for each invocation ofGoal
theCleanup
will be called exactly once.- The implementation dependence of 1c is caused by the varying indexing abilities of Prolog processors. Note, that a particular processor may execute a goal
call(call(Goal) ; fail)
ascall(Goal)
and vice versa.- When a cut is encountered, removing otherwise possible solutions, the Cleanup is called at the place (and with the bindings) of the cut.
- A Cleanup triggered by a ! is performed after the ! has removed alternatives. a149 1
call(Setup), call(Goal)
is true, and Cleanup did not
d114 1
a114 1
another throw/1
, this "ball" is lost.
@
1.4
log
@*** empty log message ***
@
text
@d72 1
a72 1
interrupts call_cleanup/2
can cause leakage of resources:
d110 1
a110 1
of throw/1
is passed, regardless
@
1.3
log
@Spelling
@
text
@d148 1
a148 1
fail) as call(Goal)
.
@
1.2
log
@Note style
@
text
@d106 1
a106 1
executes a throw/1
(explicitely or implicitely — 7.8.9 a or
d117 2
a118 2
(explicitely or implicitely) that concerns the cutparent of Goal.
A cut is performed implictely for (->)/2 - if-then (7.8.7), (;)/2 -
d127 1
a127 1
the setup are all present, wheras the bindings of goal depend on the
d146 1
a146 1
varying indexing abilties of Prolog processors. Note, that a
d197 1
a197 1
The different outcomes (labelled either/or) are due to the d211 1 a211 1 Suceeds, unifying X = 1. @ 1.1 log @Initial revision @ text @d16 5 d51 1 a51 1
NOTE — A built-in predicate call_cleanup/2
is
d76 1
a76 1
protected as a separate argument.
d136 2
a137 1
NOTES
d157 2
@