Prolog "kernel"
Admin User, erstellt 07. Apr. 2025
/**
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
/**
* Source of test cases are the following standards:
* - Prolog General Core ISO/IEC 13211-1
*/
runner_file(control, kernel, 'ISO 7.8 catch').
/****************************************************************/
/* Kernel Predicates */
/****************************************************************/
/* fail */
runner_pred(fail, 0, control, kernel, 'ISO 7.8.2.4').
runner_case(fail, 0, control, kernel, 'ISO 7.8.2.4, ISO 1') :-
\+ fail.
/* true */
runner_pred(true, 0, control, kernel, 'ISO 7.8.1.4').
runner_case(true, 0, control, kernel, 'ISO 7.8.1.4, ISO 1') :-
true.
/* ! */
runner_pred(!, 0, control, kernel, 'ISO 7.8.4.4').
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 1') :- !.
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 2') :-
\+ (!, fail; true).
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 3') :-
(call(!), fail; true).
twice(!).
twice(true).
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 4') :-
findall(hit, (twice(_), !), L), L==[hit].
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 5') :-
findall(hit, ((!; twice(_)), twice(true)), L), L==[hit].
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 6') :-
findall(hit, (twice(_), (twice(true); !), twice(true)), L), L==[hit, hit].
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 7') :-
\+ (twice(_), (!, fail; write('No '))).
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 8') :-
findall(hit, (twice(X), call(X)), L), L==[hit, hit].
goal((twice(_), !)).
goal(true).
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 9') :-
findall(hit, (goal(X), call(X)), L), L==[hit, hit].
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 10') :-
findall(hit, (twice(_), \+ \+ !), L), L==[hit, hit].
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 11') :-
findall(hit, (twice(_), once(!)), L), L==[hit, hit].
runner_case(!, 0, control, kernel, 'ISO 7.8.4.4, ISO 12') :-
findall(hit, (twice(_), call(!)), L), L==[hit, hit].
/* halt(N) */
/* catch(A, E, B) */
runner_pred(catch, 3, control, kernel, 'ISO 7.8.9.4').
runner_case(catch, 3, control, kernel, 'ISO 7.8.9.4, ISO 1') :-
catch(foo(5), test(Y), true), Y==10.
bar(X) :- X = Y, throw(Y).
runner_case(catch, 3, control, kernel, 'ISO 7.8.9.4, ISO 2') :-
catch(bar(3), Z, true), Z==3.
runner_case(catch, 3, control, kernel, 'ISO 7.8.9.4, ISO 3') :-
catch(true, _, 3).
runner_case(catch, 3, control, kernel, 'ISO 7.8.9.4, ISO 4a') :-
catch(true, _, fail).
runner_case(catch, 3, control, kernel, 'ISO 7.8.9.4, ISO 4b') :-
catch((catch(true, _, fail), throw(bla)), E, true), E==bla.
car(X) :- X = 1, throw(X).
runner_case(catch, 3, control, kernel, 'ISO 7.8.9.4, ISO 5a') :-
catch(car(_), Y, true), Y==1.
runner_case(catch, 3, control, kernel, 'ISO 7.8.9.4, ISO 5b') :-
catch(car(X), _, true), var(X).
runner_case(catch, 3, control, kernel, 'ISO 7.8.9.4, ISO 6') :-
\+ catch(number_codes(_, "1a0"), error(syntax_error(_),_), fail).
coo(X) :- throw(X).
g :- catch(p, _, write(h2)), coo(c).
p.
p :- throw(b).
runner_case(catch, 3, control, kernel, 'ISO 7.8.9.4, ISO 7') :-
catch(g, C, true), C==c.
runner_case(catch, 3, control, kernel, 'ISO 7.8.9.4, ISO 8') :-
catch(coo(_), error(E,_), true), E==instantiation_error.
/* set_prolog_flag(F,V) */
runner_pred(set_prolog_flag, 2, control, kernel, 'ISO 8.17.1.4').
runner_case(set_prolog_flag, 2, control, kernel, 'ISO 8.17.1.4, ISO 1') :-
catch(set_prolog_flag(max_arity, 1000), error(E, _), true),
E == permission_error(modify, flag, max_arity).
runner_case(set_prolog_flag, 2, control, kernel, 'ISO 8.17.1.4, ISO 2') :-
catch(set_prolog_flag(argv, [123]), error(E, _), true),
E == type_error(atom, 123).
runner_case(set_prolog_flag, 2, control, kernel, 'ISO 8.17.1.4, ISO 3') :-
catch(set_prolog_flag(123, 'July 1988'), error(E,_), true),
E == type_error(atom, 123).
/* current_prolog_flag(F,V) */
runner_pred(current_prolog_flag, 2, control, kernel, 'ISO 8.17.2.4').
runner_case(current_prolog_flag, 2, control, kernel, 'ISO 8.17.2.4, XLOG 1') :-
current_prolog_flag(max_arity, X),
integer(X).
runner_case(current_prolog_flag, 2, control, kernel, 'ISO 8.17.2.4, XLOG 2') :-
current_prolog_flag(X, Y), X = double_quotes,
atom(Y).
runner_case(current_prolog_flag, 2, control, kernel, 'ISO 8.17.2.4, XLOG 3') :-
catch(current_prolog_flag(date, _), error(E,_), true),
E == domain_error(prolog_flag, date).