Prolog "logue"
Admin User, created Oct 25. 2024
/**
* Prolog code for the Prologue to Prolog test cases.
*
* Source of test cases are the following standards:
* - A Prologue for Prolog, N235 WG17, Ulrich Neumerkel
* <a href="https://www.complang.tuwien.ac.at/ulrich/iso-prolog/prologue">www.complang.tuwien.ac.at/ulrich/iso-prolog/prologue</a>
*
* 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.
*/
runner_file(structure, logue, 'N235 lists').
/****************************************************************/
/* Lists */
/****************************************************************/
/* append(X, Y, Z) */
runner_pred(append,3, structure, logue, 'N235 2').
runner_case(append,3, structure, logue, 'N235 2, ISO 1') :-
append([a,b], [c], X),
X == [a, b, c].
runner_case(append,3, structure, logue, 'N235 2, XLOG 1') :-
append(X, [c], [a,b,c]),
X == [a, b].
runner_case(append,3, structure, logue, 'N235 2, XLOG 2') :-
append([a,b], X, [a,b,c]),
X == [c].
runner_case(append,3, structure, logue, 'N235 2, XLOG 3') :-
findall(X-Y, append(X, Y, [a,b,c]), L),
L == [[]-[a, b, c], [a]-[b, c], [a, b]-[c], [a, b, c]-[]].
/* reverse(X, Y) */
runner_pred(reverse,2, structure, logue, 'XLOG 4.5.2').
runner_case(reverse,2, structure, logue, 'XLOG 4.5.2, XLOG 1') :-
reverse([a,b,c], X), X == [c,b,a].
runner_case(reverse,2, structure, logue, 'XLOG 4.5.2, XLOG 2') :-
\+ reverse([a|foo], _).
runner_case(reverse,2, structure, logue, 'XLOG 4.5.2, XLOG 3') :-
reverse(X, Y), X == [], Y == [].
/* member(X, Y) */
runner_pred(member,2, structure, logue, 'N235 1').
runner_case(member,2, structure, logue, 'N235 1, XLOG 1') :-
member(b, [a,b,c]).
runner_case(member,2, structure, logue, 'N235 1, XLOG 2') :-
\+ member(d, [a,b,c]).
runner_case(member,2, structure, logue, 'N235 1, XLOG 3') :-
findall(X, member(X, [a,b,c]), L),
L == [a, b, c].
/* select(X, Y, Z) */
runner_pred(select,3, structure, logue, 'N235 5').
runner_case(select,3, structure, logue, 'N235 5, XLOG 1') :-
select(b, [a,b,c], X),
X == [a, c].
runner_case(select,3, structure, logue, 'N235 5, XLOG 2') :-
\+ select(d, [a,b,c], _).
runner_case(select,3, structure, logue, 'N235 5, XLOG 3') :-
findall(X-Y, select(X, [a,b,c], Y), L),
L == [a-[b, c], b-[a, c], c-[a, b]].
runner_case(select,3, structure, logue, 'N235 5, XLOG 4') :-
findall(X, select(c, X, [a,b]), L),
L == [[c, a, b], [a, c, b], [a, b, c]].
/* length(X, Y) */
runner_pred(length,2, structure, logue, 'N235 3').
runner_case(length,2, structure, logue, 'N235 3, ISO 1') :-
length([a,b,c], N), N == 3.
runner_case(length,2, structure, logue, 'N235 3, ISO 2') :-
length(L, 3), length(L, N), N == 3.
runner_case(length,2, structure, logue, 'N235 3, XLOG 1') :-
\+ length([a|foo], _).
runner_case(length,2, structure, logue, 'N235 3, XLOG 2') :-
length(X, Y), X == [], Y == 0.
/****************************************************************/
/* Arithmetic */
/****************************************************************/
/* between(X, Y, Z) */
runner_pred(between,3, structure, logue, 'N235 4').
runner_case(between,3, structure, logue, 'N235 4, ISO 1') :-
\+ between(1, 2, 0).
runner_case(between,3, structure, logue, 'N235 4, ISO 2a') :-
findall(I, between(1, 2, I), [Y|_]), Y == 1.
runner_case(between,3, structure, logue, 'N235 4, ISO 2b') :-
findall(I, between(1, 2, I), [_,Y|_]), Y == 2.
runner_case(between,3, structure, logue, 'N235 4, ISO 2c') :-
findall(I, between(1, 2, I), [_,_]).
runner_case(between,3, structure, logue, 'N235 4, ISO 3') :-
catch(between(1, _, 2), error(E,_), true),
E == instantiation_error.
runner_case(between,3, structure, logue, 'N235 4, ISO 4') :-
catch(between(_, 1, 0), error(E,_), true),
E == instantiation_error.
runner_case(between,3, structure, logue, 'N235 4, ISO 5') :-
catch(between(1,c,_), error(E,_), true),
E == type_error(integer, c).
runner_case(between,3, structure, logue, 'N235 4, ISO 6') :-
catch(between(1+1,2,_), error(E,_), true),
E == type_error(integer, 1+1).
/****************************************************************/
/* Set Predicates */
/****************************************************************/
/* findall(T, G, L) */
runner_pred(findall, 3, structure, logue, 'ISO 8.10.1.4').
runner_case(findall, 3, structure, logue, 'ISO 8.10.1.4, ISO 1') :-
findall(X, (X = 1; X = 2), S),
S == [1, 2].
runner_case(findall, 3, structure, logue, 'ISO 8.10.1.4, ISO 2') :-
findall(X+Y, X = 1, S),
nonvar(S), S = [1+Z], Z \== Y.
runner_case(findall, 3, structure, logue, 'ISO 8.10.1.4, ISO 3') :-
findall(_, fail, S),
S == [].
runner_case(findall, 3, structure, logue, 'ISO 8.10.1.4, ISO 4') :-
findall(X, (X = 1; X = 1), S),
S == [1, 1].
runner_case(findall, 3, structure, logue, 'ISO 8.10.1.4, ISO 5') :-
\+ findall(X, (X = 2; X = 1), [1, 2]).
runner_case(findall, 3, structure, logue, 'ISO 8.10.1.4, ISO 7') :-
findall(X, (X = 1; X = 2), [X,Y]),
X == 1, Y == 2.
runner_case(findall, 3, structure, logue, 'ISO 8.10.1.4, ISO 8') :-
catch(findall(_, _, _), error(E, _), true),
E == instantiation_error.
runner_case(findall, 3, structure, logue, 'ISO 8.10.1.4, ISO 9') :-
catch(findall(_, 4, _), error(E, _), true),
E == type_error(callable, 4).