|
5 | 5 | :- use_module(library(format)).
|
6 | 6 | :- use_module(library(debug)).
|
7 | 7 | :- use_module(library(time)).
|
8 |
| - |
9 |
| -:- dynamic(rznvivy/0). |
| 8 | +:- use_module(library(gensym)). |
10 | 9 |
|
11 | 10 | % Asserting and consulting of erroneous arithmetic relation shall succeed,
|
12 | 11 | % but then it must fail at runtime.
|
13 | 12 | main :-
|
14 |
| - template_relation("ttftf", R), |
15 |
| - ignore_exception(test(R, consult)), |
16 |
| - %ignore_exception(test(R, assert)), |
17 |
| - true. |
| 13 | + template_relation("tttft", R), |
| 14 | + load_test(assertz, R), |
| 15 | + load_test(reconsult, R). |
18 | 16 |
|
19 |
| -test(Relation, TestVariant) :- |
20 |
| - load_and_call(TestVariant, rznvivy/0, (rznvivy :- false, Relation), \+rznvivy). |
| 17 | +load_test(Setup, Body) :- |
| 18 | + portray_clause(start:Setup), |
| 19 | + gensym(test, Test), |
| 20 | + setup_call_cleanup( |
| 21 | + ignore_exception(call(Setup, (Test :- false, Body))), |
| 22 | + ( |
| 23 | + (ignore_exception(listing(Test/0)),!;true), |
| 24 | + \+ignore_exception(Test) -> Result = pass; Result = fail |
| 25 | + ), |
| 26 | + ignore_exception(retractall(Test)) |
| 27 | + ), |
| 28 | + portray_clause(Result:Setup). |
21 | 29 |
|
22 |
| -load_and_call(assert, PI, Clause, Query) :- |
| 30 | +reconsult(Clause) :- |
| 31 | + Clause = (Head :- Body), |
| 32 | + File = 'chnytjl.pl', |
| 33 | + portray_consult(File, (canary :- Body)), |
23 | 34 | setup_call_cleanup(
|
24 |
| - ignore_exception(assertz(Clause)), |
25 |
| - callf(PI, Query), |
26 |
| - $retract(Clause) |
| 35 | + assertz(Head), |
| 36 | + portray_consult(File, Clause), |
| 37 | + retract(Head) |
27 | 38 | ).
|
28 |
| -load_and_call(consult, PI, Clause, Query) :- |
29 |
| - T = 'chnytjl.pl', |
| 39 | + |
| 40 | +portray_consult(File, Clause) :- |
30 | 41 | setup_call_cleanup(
|
31 |
| - open(T, write, S), |
| 42 | + open(File, write, S), |
32 | 43 | portray_clause(S, Clause),
|
33 | 44 | close(S)
|
34 | 45 | ),
|
35 |
| - setup_call_cleanup( |
36 |
| - ignore_exception(consult(T)), |
37 |
| - callf(PI, Query), |
38 |
| - $retract(Clause) |
39 |
| - ). |
40 |
| - |
41 |
| -callf(PI, G_0) :- |
42 |
| - clause(rznvivy, I), |
43 |
| - I \= true, |
44 |
| - always(ignore_exception(listing(PI))), |
45 |
| - $G_0. |
46 |
| - |
47 |
| -always(G_0) :- call(G_0). |
48 |
| -always(_). |
| 46 | + consult(File). |
49 | 47 |
|
50 | 48 | template_relation(Template, R) :-
|
51 | 49 | time(setof(E, phrase(arith_relation(E), Template), Es)),
|
|
0 commit comments