head 1.32; access; symbols; locks ulrich:1.32; strict; comment @# @; 1.32 date 2024.03.15.14.00.50; author ulrich; state Exp; branches; next 1.31; 1.31 date 2024.03.12.09.38.41; author ulrich; state Exp; branches; next 1.30; 1.30 date 2024.03.11.09.07.06; author ulrich; state Exp; branches; next 1.29; 1.29 date 2024.03.11.07.26.06; author ulrich; state Exp; branches; next 1.28; 1.28 date 2024.03.05.07.28.47; author ulrich; state Exp; branches; next 1.27; 1.27 date 2024.03.05.07.11.56; author ulrich; state Exp; branches; next 1.26; 1.26 date 2024.03.05.07.07.44; author ulrich; state Exp; branches; next 1.25; 1.25 date 2023.08.12.03.38.50; author ulrich; state Exp; branches; next 1.24; 1.24 date 2023.08.12.03.30.15; author ulrich; state Exp; branches; next 1.23; 1.23 date 2023.06.26.08.19.11; author ulrich; state Exp; branches; next 1.22; 1.22 date 2023.06.08.08.25.54; author ulrich; state Exp; branches; next 1.21; 1.21 date 2022.08.26.16.30.19; author ulrich; state Exp; branches; next 1.20; 1.20 date 2022.07.26.14.29.27; author ulrich; state Exp; branches; next 1.19; 1.19 date 2022.05.18.09.44.52; author ulrich; state Exp; branches; next 1.18; 1.18 date 2022.05.11.09.35.33; author ulrich; state Exp; branches; next 1.17; 1.17 date 2019.06.01.13.01.18; author ulrich; state Exp; branches; next 1.16; 1.16 date 2018.07.07.15.06.07; author ulrich; state Exp; branches; next 1.15; 1.15 date 2014.11.30.23.28.58; author ulrich; state Exp; branches; next 1.14; 1.14 date 2014.04.13.21.43.16; author ulrich; state Exp; branches; next 1.13; 1.13 date 2013.11.29.09.15.30; author ulrich; state Exp; branches; next 1.12; 1.12 date 2012.09.06.06.16.53; author ulrich; state Exp; branches; next 1.11; 1.11 date 2012.08.21.12.01.20; author ulrich; state Exp; branches; next 1.10; 1.10 date 2012.07.08.14.44.17; author ulrich; state Exp; branches; next 1.9; 1.9 date 2012.07.06.15.56.18; author ulrich; state Exp; branches; next 1.8; 1.8 date 2012.07.06.15.54.01; author ulrich; state Exp; branches; next 1.7; 1.7 date 2012.07.06.15.49.14; author ulrich; state Exp; branches; next 1.6; 1.6 date 2012.07.06.15.47.56; author ulrich; state Exp; branches; next 1.5; 1.5 date 2012.07.06.15.23.55; author ulrich; state Exp; branches; next 1.4; 1.4 date 2012.07.06.15.19.52; author ulrich; state Exp; branches; next 1.3; 1.3 date 2012.07.06.15.17.52; author ulrich; state Exp; branches; next 1.2; 1.2 date 2012.07.04.16.42.44; author ulrich; state Exp; branches; next 1.1; 1.1 date 2012.06.29.12.58.42; author ulrich; state Exp; branches; next ; desc @@ 1.32 log @*** empty log message *** @ text @ post-N290 Prolog prologue (Working draft)

ISO/IEC JTC1 SC22 WG17 post-N290
A Prologue for Prolog (working draft)

Ulrich Neumerkel, 2023-06-26

Motivation

Many commonly used predicates are not part of the Prolog standard core. Current Prolog processors differ in the way how they provide these predicates. They may reside in a library, or are imported from a module, or may be built-in predicates and therefore implementation specific extensions due to 5.5.9. In the past, discussions on this level have prevented defining these predicates.

The aim of the Prolog prologue is to avoid discussing such details and concentrate on the identification and precise definition of these commonly used predicates instead. The Prolog prologue is a possibly empty file to be included (7.4.2.7). After inclusion, the following predicates are defined. A processor may provide also some other means to include the prologue. For example, via a command line switch.

History

2011-07-10: WG17 resolution.
2012-07-06: First announcement on PROLOG-STANDARD
2022-05-09: Queries with answer descriptions used in examples

Status quo

The following is defined by IS 13211-1:1995 and IS 13211-2:2000. Changes by Cor.2:2012 link to the draft (but not to the actual ISO/IEC document, you have to download it), additions are bold green links. Further, changes by Cor.3:2017 link rather to the working draft.
Part 1: General core
7.4.2 Directives
1 dynamic/1. 2 multifile/1. 3 discontiguous/1. 4 op/3. 5 char_conversion/2. 6 initialization/1. 7 include/1. 8 ensure_loaded/1. 9 set_prolog_flag/2.
7.8 Control constructs
1 true/0. 2 fail/0. 3 call/1. 4 !/0. 5 (',')/2. 6 (;)/2 – disjunction. 7 (->)/2. 8 (;)/2 – if-then-else. 9 catch/3. 10 throw/1.
7.10.2.13 Stream properties
file_name/1. mode/1. input/0. output/0. alias/1. position/1. end_of_stream/1. eof_action/1. reposition/1. type/1.
7.10.3 Read-options list
variables/1. variable_names/1. singletons/1.
7.10.4 Write-options list
quoted/1. ignore_ops/1. variable_names/1. numbervars/1.
7.11.1 Flags defining integer type I
1 bounded. 2 max_integer. 3 min_integer. 4 integer_rounding_function.
7.11.2 Other flags
1 char_conversion. 2 debug. 3 max_arity. 4 unknown. 5 double_quotes.
7.12.2 Error classification
a) instantiation_error. b) type_error. c) domain_error. d) existence_error. e) permission_error. f) representation_error. g) evaluation_error. h) resource_error. i) syntax_error. j) system_error. k) uninstantiation_error.
8.2 Term unification
1 (=)/2. 2 unify_with_occurs_check/2. 3 (\=)/2. 4 subsumes_term/2.
8.3 Type testing
1 var/1. 2 atom/1. 3 integer/1. 4 float/1. 5 atomic/1. 6 compound/1. 7 nonvar/1. 8 number/1. 9 callable/1. 10 ground/1. 11 acyclic_term/1.
8.4 Term comparison
1 (@@=<)/2, (==)/2, (\==)/2, (@@<)/2, (@@>)/2, (@@>=)/2. 2 compare/3. 3 sort/2. 4 keysort/2.
8.5 Term creation and decomposition
1 functor/3. 2 arg/3. 3 (=..)/2. 4 copy_term/2 5 term_variables/2.
8.6 Arithmetic evaluation
1 (is)/2.
8.7 Arithmetic comparison
1 (=:=)/2, (=\=)/2, (<)/2, (=<)/2, (>)/2, (>=)/2.
8.8 Clause retrieval and information
1 clause/2. 2 current_predicate/1.
8.9 Clause creation and destruction
1 asserta/1. 2 assertz/1. 3 retract/1. 4 abolish/1. 5 retractall/1.
8.10 All solutions
1 findall/3. 2 bagof/3. 3 setof/3.
8.11 Stream selection and control
1 current_input/1. 2 current_output/1. 3 set_input/1. 4 set_output/1. 5 open/4, open/3. 6 close/2, close/1. 7 flush_output/1, flush_output/0. 8 stream_property/2, at_end_of_stream/0, at_end_of_stream/1. 9 set_stream_position/2.
8.12 Character input/output
1 get_char/2, get_char/1, get_code/1, get_code/2. 2 peek_char/2, peek_char/1, peek_code/1, peek_code/2. 3 put_char/2, put_char/1, put_code/1, put_code/2, nl/0, nl/1.
8.13 Byte input/output
1 get_byte/2, get_byte/1. 2 peek_byte/2, peek_byte/1. 3 put_byte/2, put_byte/1.
8.14 Term input/output
1 read_term/3, read_term/2, read/1, read/2. 2 write_term/3, write_term/2, write/1, write/2, writeq/1, writeq/2, write_canonical/1, write_canonical/2. 3 op/3. 4 current_op/3. 5 char_conversion/2. 6 current_char_conversion/2.
8.15 Logic and control
1 (\+)/1. 2 once/1. 3 repeat/0. 4 call/2..8. 5 false/0.
8.16 Atomic term processing
1 atom_length/2. 2 atom_concat/3. 3 sub_atom/5. 4 atom_chars/2. 5 atom_codes/2. 6 char_code/2. 7 number_chars/2. 8 number_codes/2.
8.17 Implementation defined hooks
1 set_prolog_flag/2. 2 current_prolog_flag/2. 3 halt/0. 4 halt/1.
9.1 The simple arithmetic functors
(+)/2, (-)/2, (*)/2, (//)/2, (/)/2, (rem)/2, (mod)/2, (-)/1, abs/1, sign/1, float_integer_part/1, float_fractional_part/1, float/1, floor/1, truncate/1, round/1, ceiling/1, (+)/1, (div)/2.
9.3 Other arithmetic functors
1 (**)/2. 2 sin/1. 3 cos/1. 4 atan/1. 5 exp/1. 6 log/1. 7 sqrt/1. 8 max/2. 9 min/2. 10 (^)/2. 11 asin/1. 12 acos/1. 13 atan2/2. 14 tan/1. 15 pi/0.
9.4 Bitwise functors
1 (>>)/2. 2 (<<)/2. 3 (/\)/2. 4 (\/)/2. 5 (\)/1. 6 xor/2.
Part 2: Modules
7.2 Module predicates
1 current_module/1. 2 predicate_property/2.
7.3 Clause retrieval and information
2 current_predicate/1.

Proposed for Prolog prologue

The format and notation of the definition of each predicate is consistent with that used for built-in predicates (8.1). The logical condition for a predicate to be true is sometimes divided into two parts. In the first formulation a sufficient condition is given, using "if". This condition often corresponds to the intended use of a predicate. The second formulation starts with "More precisely," and gives a necessary and sufficient condition using "iff".
p.p Prolog prologue
1 member/2. 2 append/3. 3 length/2. 4 between/3. 5 select/3. 6 succ/2. 7 maplist/2..8. 8 nth0/3, nth1/3, nth0/4, nth1/4. 9 call_nth/2. 10 foldl/4..6.
further propositions:
countall/2
crypto_data_hash/3 (local, versions)

p.p.1 member/2

p.p.1.1 Description

member(X, L) is true if X is an element of the list L.

More precisely, member(X, L) is true iff X is an element of a list prefix of L.

Procedurally, member/2 is defined with the following clauses.

member(X, [X|_L]).
member(X, [_|L]) :-
   member(X, L).
Alternatively:
member(X, [E|L]) :-
   (  X = E
   ;  member(X, L)
   ).

p.p.1.2 Template and modes

member(?term, ?term)

p.p.1.3 Errors

None.

p.p.1.4 Examples

?- member(X, [1,2]).
   X = 1
;  X = 2.

?- member(1, L).
   L = [1|_A]
;  L = [_A,1|_B]
;  L = [_A,_B,1|_C]
;  ... . % ad infinitum

?- member(X, [Y,Z|nonlist]).
   X = Y
;  X = Z.

?- member(X, nonlist).
   false.

?- member(X, X).
   sto, loops % occurs-check
|  sto,
   X = [X|_A]
;  X = [_A,X|_B]
;  X = [_A,_B,X|_C]
;  ...        % rational trees
|  sto,
   X = [_A|_B]
;  X = [_A,[_A,[_A|_B]|_C]|_C]
;  X = [_A,_B,[_A,_B,[_A,_B|_C]|_D]|_D]
;  ... .      % literal substitutions

p.p.2 append/3

p.p.2.1 Description

append(Xs, Ys, Zs) is true if Zs is the concatenation of the lists Xs and Ys.

More precisely, append(Xs, Ys, Zs) is true iff the list Xs is a list prefix of Zs and Ys is Zs with prefix Xs removed.

Procedurally, append/3 is defined with the following clauses.

append([], Zs, Zs).
append([X|Xs], Ys, [X|Zs]) :-
   append(Xs, Ys, Zs).

p.p.2.2 Template and modes

append(?term, ?term, ?term)

p.p.2.3 Errors

None.

p.p.2.4 Examples

?- append([a,b],[c,d], Xs).
   Xs = [a,b,c,d].

?- append([a], nonlist, Xs).
   Xs = [a|nonlist].

?- append([a], Ys, Zs).
   Zs = [a|Ys].

?- append(Xs, Ys, [a,b,c]).
   Xs = [], Ys = [a,b,c]
;  Xs = [a], Ys = [b,c]
;  Xs = [a,b], Ys = [c]
;  Xs = [a,b,c], Ys = [].

?- append(Xs, Ys, [a,b|Xs]).
   Xs = [], Ys = [a,b]
;  Xs = [a], Ys = [b,a]
;  Xs = [a,b], Ys = [a,b]
;  Xs = [a,b,a], Ys = [b,a]
;  ... . % ad infinitum

p.p.3 length/2

p.p.3.1 Description

length(List, Length) is true iff List is a list of length Length.

Procedurally, length(List, Length) is executed as follows:
a) If List is neither a partial list nor a list, then the goal fails.
b) If List is a list, then unifies Length with the length of List.
c) Else the goal fails.
d) If Length is an integer, then unifies List with a list of length Length with Length distinct fresh variables as elements.
e) Else the goal fails.
f) Chooses the first element Len of N0 being the integer 0.
g) The goal succeeds, unifying Length with Len and List with a list of length Len with Len distinct fresh variables as elements.
h) If List is a partial list and Length is a variable, chooses the next element Len of N0 and proceeds to step p.p.3.1 g.
i) Else the goal fails.

length(List, Length) is re-executable. On backtracking, continue at p.p.3.1 h above.

p.p.3.2 Template and modes

length(?term, ?integer)

p.p.3.3 Errors

a) Length is neither a variable nor an integer
type_error(integer, Length).
b) Length is an integer that is less than zero
domain_error(not_less_than_zero, Length).

p.p.3.4 Examples

?- length([a,b,c], Length).
   Length = 3.

?- length(List, 5).
   List = [_A,_B,_C,_D,_E].

?- length(List, Length).
   List = [], Length = 0
;  List = [_A], Length = 1
;  List = [_A,_B], Length = 2
;  ... . % Ad infinitum.

p.p.4 between/3

p.p.4.1 Description

between(Lower, Upper, X) is true iff X is greater than or equal to Lower, and less than or equal to Upper.

Procedurally, between(Lower, Upper, X) is defined with the following clauses when no error conditions apply.
between(Lower, Upper, Lower) :-
   Lower =< Upper.
between(Lower1, Upper, X) :-
   Lower1 < Upper,
   Lower2 is Lower1 + 1,
   between(Lower2, Upper, X).

p.p.4.2 Template and modes

between(+integer,+integer,?integer)

p.p.4.3 Errors

a) Lower is a variable
instantiation_error.
b) Upper is a variable
instantiation_error.
c) Lower is neither a variable nor an integer
type_error(integer, Lower).
d) Upper is neither a variable nor an integer
type_error(integer, Upper).
e) X is neither a variable nor an integer
type_error(integer, X).
NOTE — There are goals with a unique solution that still require an instantiation error. E.g.: between(X, X, 1).

p.p.4.4 Examples

?- between(1, 2, 0).
   false.

?- between(1, 2, I).
   I = 1
;  I = 2.

?- between(2, 1, I).
   false.

?- between(I, I, 0).
   instantiation_error.

?- between(1, I, 0).
   instantiation_error.

?- between(I, -1, 0).
   instantiation_error.

?- between(1, c, 0).
   type_error(integer, c).

?- between(1+1,2,I).
   type_error(integer, 1+1).

p.p.5 select/3

select(X, Xs, Ys) is true if X is an element of the list Xs and Ys is the list Xs with one occurrence of X removed.

Procedurally, select/3 is defined with the following clauses.

select(E, [E|Xs], Xs).
select(E, [X|Xs], [X|Ys]) :-
   select(E, Xs, Ys).

p.p.5.2 Template and modes

select(?term, ?term, ?term)

p.p.5.3 Errors

None.

p.p.5.4 Examples

?- select(X, [1,2], Xs).
   X = 1, Xs = [2]
;  X = 2, Xs = [1].

?- select(X, [Y|nonlist], Xs).
   X = Y, Xs = nonlist.

?- select(E, Xs, Xs).
   sto, loops
|  sto,
   Xs = [E|Xs]
;  Xs = [_A,E|_B], _B = [E|_B]
;  ... .

p.p.6 succ/2

p.p.6.1 Description

succ(X, S) is true iff S is the successor of the non-negative integer X.

Procedurally, succ(X, S) is defined with the following clauses when no error conditions apply.
succ(X, S) :-
   ( nonvar(S) -> S > 0, X is S-1 ; S is X+1 ).

p.p.6.2 Template and modes

succ(?integer,+integer)
succ(+integer,-integer)

p.p.6.3 Errors

a) X is a variable and S is a variable.
instantiation_error.
b) X is neither a variable nor an integer
type_error(integer, X).
c) S is neither a variable nor an integer
type_error(integer, S).
d) X is an integer that is less than zero
domain_error(not_less_than_zero, X).
e) S is an integer that is less than zero
domain_error(not_less_than_zero, S).
f) Flag bounded is true and X is maxint and S is a variable.
evaluation_error(int_overflow).
repesentation_error(max_integer).
NOTE — succ(X, X) requires an instantiation error although there is no solution.

p.p.6.4 Examples

?- succ(X, S).
   instantiation_error.

?- succ(X, X).
   instantiation_error.

?- succ(0, S).
   S = 1.

?- succ(1, 1+1).
   type_error(integer, 1+1).

?- succ(X, 0).
   false.

?- succ(-1, S).
   domain_error(not_less_than_zero, -1).

?- current_prolog_flag(max_integer, MI), succ(MI, 0).
   false.

?- current_prolog_flag(max_integer, MI), succ(MI, 1).
   false.

?- current_prolog_flag(max_integer, MI), succ(MI, MI).
   false.

?- current_prolog_flag(max_integer, MI), succ(MI, S).
   false
|  evaluation_error(int_overflow)
|  representation_error(max_integer).

p.p.7 maplist/2..8

p.p.7.1 Description

maplist(R_1, E1s) is true iff E1s is a list and for each element E1 of E1s, call(R_1, E1) is true.

maplist(R_2, E1s, E2s) is true iff E1s and E2s are lists of same length and for each element E1 of E1s and each corresponding element of E2, call(R_2, E1, E2) is true.

maplist(R_n, E1s, E2s, ... Ens) is true iff E1s, E2s up to Ens are lists of same length and call(R_n, E1_i, E2_i, ... En_i) is true for each i where Ek_i is the i-th element of Listk.

Procedurally, maplist/2..8 is defined with the following clauses.

maplist(_R_1, []).
maplist(R_1, [E1|E1s]) :-
   call(R_1, E1),
   maplist(R_1, E1s).

maplist(_R_2, [], []).
maplist(R_2, [E1|E1s], [E2|E2s]) :-
   call(R_2, E1, E2),
   maplist(R_2, E1s, E2s).

maplist(_R_3, [], [], []).
maplist(R_3, [E1|E1s], [E2|E2s], [E3|E3s]) :-
   call(R_3, E1, E2, E3),
   maplist(R_3, E1s, E2s, E3s).

...

maplist(_R_n, [], [], ... []).
maplist(R_n, [E1|E1s], [E2|E2s], ... [En|Ens]) :-
   call(R_n, E1, E2, ... En),
   maplist(R_n, E1s, E2s, ... Ens).

p.p.7.2 Template and modes

maplist(?term, ?term)
maplist(?term, ?term, ?term)
maplist(?term, ?term, ?term, ?term)
...
maplist(?term, ?term, ?term, ... ?term)

p.p.7.3 Errors

None.

p.p.7.4 Examples

?- maplist(>(3), [1, 2]).
   true.

?- maplist(>(3), [1, 2, 3]).
   false.

?- maplist(=(X), Xs).
   Xs = []
;  Xs = [X]
;  Xs = [X, X]
;  Xs = [X, X, X]
;  ... . % Ad infinitum.

p.p.8 nth0/4, nth0/3, nth1/4, nth1/3

p.p.8.1 Description

nth0(N, Es0, E, Es) is true if E is an element of the list Es0 and there are N elements before E. Es is the list without this occurence of E.

More precisely, nth0(N, Es0, E, Es) is true iff there is a list prefix Prefix of Es0 and length(Prefix,N), append(Prefix,[E|Postfix], Es0), append(Prefix, Postfix, Es) is true.

p.p.8.2 Template and modes

nth0(?integer, ?term, ?term, ?term)
nth0(?integer, ?term, ?term)
nth1(?integer, ?term, ?term, ?term)
nth1(?integer, ?term, ?term)

p.p.8.3 Errors

a) N is neither a variable nor an integer
type_error(integer, N).
b) N is an integer that is less than zero
domain_error(not_less_than_zero, N).
NOTE — @@@@@@

p.p.8.4 Examples

?- nth0(1, [a,b,c], E).
   E = b.

?- nth0(N, [a,b,c], E).
   N = 0, E = a
;  N = 1, E = b
;  N = 2, E = c.

?- nth0(0, [A,B|non_list], E).
   A = E.

?- nth0(2, Es, E).
   Es = [_A,_B,E|_C].

?- nth0(N, Es, E).
   N = 0, Es = [E|_A]
;  N = 1, Es = [_A,E|_B]
;  N = 2, Es = [_A,_B,E|_C]
;  N = 3, Es = [_A,_B,_C,E|_D]
;  ... .

?- nth0(non_integer, Es, E).
   type_error(integer, non_integer).

?- nth0(-1, Es, E).
   domain_error(not_less_than_zero, -1).

?- nth0(N, [[]|Es], Es).
   N = 0, Es = []
;  sto, loops
|  N = 0, Es = []
;  sto, N = 1, Es = [Es|_A]
;  ... .

?- nth1(0, Es, E).
   false.

p.p.8.5 Bootstrapped built-in predicates

The built-in predicates nth0/3, nth1/4, and nth1/3 all provide similar functionality to nth0/4.
nth0(N, Es0, E) :-
   nth0(N, Es0, E, _).

nth1(N, Es0, E, Es) :-
   N \== 0,
   nth0(N, [_|Es0], E, [_|Es]),
   N \== 0.

nth1(N, Es0, E) :-
   nth1(N, Es0, E, _).

p.p.9 call_nth/2

post-N288

p.p.10 foldl/4..6

p.p.10.1 Description

foldl(R_3, Xs, S0,S) is true iff Xs is a list and for all elements X1..Xn of Xs the following is true.
call(R_3, X1, S0,S1),
call(R_3, X2, S1,S2),
...,
call(R_3, Xn, Spn,S).

foldl(R_4, Xs, Ys, S0,S) is true iff Xs and Ys are lists of same length and for all elements X1..Xn of Xs and Y1..Yn of Ys the following is true.

call(R_4, X1, Y1, S0,S1),
call(R_4, X2, Y2, S1,S2),
...,
call(R_4, Xn, Yn, Spn,S).

foldl(R_5, Xs, Ys, Ys, S0,S) is true iff Xs, Ys, and Zs are lists of same length and for all elements X1..Xn of Xs, Y1..Yn of Ys, and Z1..Zn of Zs the following is true.

call(R_5, X1, Y1, Z1, S0,S1),
call(R_5, X2, Y2, Z2, S1,S2),
...,
call(R_5, Xn, Yn, Zn, Spn,S).

Procedurally, foldl/4..6 is defined with the following clauses.

foldl(_, [], S,S).
foldl(R_3, [X|Xs], S0,S) :-
   call(R_3, X, S0,S1),
   foldl(R_3, Xs, S1,S1).

foldl(_, [], [], S,S).
foldl(R_4, [X|Xs], [Y|Ys], S0,S) :-
   call(R_4, X, Y, S0,S1),
   foldl(R_4, Xs, Ys, S1,S).

foldl(_, [], [], [], S,S).
foldl(R_5, [X|Xs], [Y|Ys], [Z|Zs], S0,S) :-
   call(R_5, X, Y, Z, S0,S1),
   foldl(R_5, Xs, Ys, Zs, S1,S).

p.p.10.2 Template and modes

foldl(?term, ?term, ?term,?term)
foldl(?term, ?term, ?term, ?term,?term)
foldl(?term, ?term, ?term, ?term, ?term,?term)
NOTE — Similar functionality is called scanlist or reduce in some Prolog processors.

p.p.10.3 Errors

None.

p.p.10.4 Examples

?- foldl(append, [[1,2],[3],[4,5]], [],Xs).
   Xs = [4,5,3,1,2].

p.p.number template/2

p.p.number.1 Description

template(X, S) is true iff S is the templateessor of the non-negative integer X.

p.p.number.2 Template and modes

template(?integer,+integer)
template(+integer,-integer)

p.p.number.3 Errors

a) X is a variable and @@.
instantiation_error.
b) ...
NOTE — @@@@@@

p.p.number.4 Examples

?- true.
   true.

p.p.number.5 Bootstrapped built-in predicate


Administrativa

Version control, ISO Prolog works, Validated HTML @ 1.31 log @*** empty log message *** @ text @d414 1 a414 1 member(?term, ?term). d479 1 a479 1 append(?term, ?term, ?term). d502 7 @ 1.30 log @*** empty log message *** @ text @d374 1 a374 1
further propositions:
d406 2 a407 2 ( X = E ; member(X, L) @ 1.29 log @*** empty log message *** @ text @d377 1 a377 1 (local, versions) d1085 1 a1085 1

p.p.@@ template/2

d1087 1 a1087 1

p.p.@@.1 Description

d1092 1 a1092 1

p.p.@@.2 Template and modes

d1097 1 a1097 1

p.p.@@.3 Errors

d1113 1 a1113 1

p.p.@@.4 Examples

d1120 1 a1120 1

p.p.@@.5 Bootstrapped built-in predicate

@ 1.28 log @maplist: replace Cont_ by R_ @ text @d375 3 a377 2 countall/2 @ 1.27 log @*** empty log message *** @ text @d813 1 a813 1 maplist(Cont_1, E1s) d817 1 a817 1 call(Cont_1, E1) is true. d820 1 a820 1

maplist(Cont_2, E1s, E2s) d826 1 a826 1 call(Cont_2, E1, E2) is true. d828 1 a828 1

maplist(Cont_n, E1s, E2s, ... Ens) is true iff d831 1 a831 1 and call(Cont_n, E1_i, E2_i, ... En_i) is true for d838 14 a851 14 maplist(_Cont_1, []). maplist(Cont_1, [E1|E1s]) :- call(Cont_1, E1), maplist(Cont_1, E1s). maplist(_Cont_2, [], []). maplist(Cont_2, [E1|E1s], [E2|E2s]) :- call(Cont_2, E1, E2), maplist(Cont_2, E1s, E2s). maplist(_Cont_3, [], [], []). maplist(Cont_3, [E1|E1s], [E2|E2s], [E3|E3s]) :- call(Cont_3, E1, E2, E3), maplist(Cont_3, E1s, E2s, E3s). d855 4 a858 4 maplist(_Cont_n, [], [], ... []). maplist(Cont_n, [E1|E1s], [E2|E2s], ... [En|Ens]) :- call(Cont_n, E1, E2, ... En), maplist(Cont_n, E1s, E2s, ... Ens). @ 1.26 log @foldl/4..6 finally defined @ text @a1065 4

p.p.10.3 Errors

None. d1071 4 @ 1.25 log @*** empty log message *** @ text @d373 1 a373 1 10 foldl/4 d793 3 d996 1 a996 3

p.p.10 foldl/4..

work in progress d1000 4 a1003 2 template(X, S) is true iff S is the templateessor of the non-negative integer X. d1005 13 a1017 1

p.p.10.2 Template and modes

d1019 6 a1024 2 template(?integer,+integer)
template(+integer,-integer) d1026 13 a1038 1

p.p.10.3 Errors

d1040 3 a1042 1
d1044 17 a1060 1
a) X is a variable and @@. d1062 3 a1064 1
instantiation_error. d1066 1 a1066 1
b) ... d1068 1 a1068 1
d1071 3 a1073 1
NOTE — @@@@@@ d1079 2 a1080 2 ?- true. true. d1083 1 a1083 2

p.p.10.5 Bootstrapped built-in predicate

@ 1.24 log @*** empty log message *** @ text @d722 1 a722 1 ( nonvar(S) -> X is S-1 ; S is X+1 ). d793 2 a794 7 ?- ( current_prolog_flag(max_integer, MI) -> succ(MI, S) ; MI = unbounded ). evaluation_error(int_overflow) | representation_error(max_integer) | MI = unbounded. d796 1 a796 1 ?- current_prolog_flag(max_integer, MI), succ(MI,1). d798 5 @ 1.23 log @*** empty log message *** @ text @d101 1 a101 1
2022-05-09: Questions with answer descriptions used in examples d373 3 a375 2
further propositions:
... d716 8 @ 1.22 log @STO cases more precise @ text @d73 1 a73 1 Neumerkel, 2022-05-09 d983 39 @ 1.21 log @nth0/3 & better, underscores @ text @d426 4 a429 4 L = [1|_] ; L = [_A,1|_] ; L = [_A,_B,1|_] ; ... . % Ad infinitum. d439 1 a439 1 sto, loops d443 7 a449 1 ; ... . d578 1 a578 1 ; List = [_], Length = 1 @ 1.20 log @nth0/3 &al added, length error removed @ text @d371 2 d374 1 a374 1
further propositions:
nth/3, nth0/3, nth1/3, call_nth/2 d427 2 a428 2 ; L = [_,1|_] ; L = [_,_,1|_] d439 1 a439 2 sto, % undefined, STO 7.3.3 true d441 3 a443 1 loops. d568 1 a568 1 List = [_,_,_,_,_]. d573 1 a573 1 ; List = [_,_], Length = 2 d696 5 a700 1 sto. a702 2 d878 4 a881 3 nth0(N, Es0, E, Es) is true if of the list Es0 and Es is the list after position @@@@@@. d885 4 a888 1 nth0(N, Es0, E, Es) is true iff (@@list prefix) d968 1 a968 1 nth0(N, [_|Es0], E, Es), d976 1 d978 1 a978 34

p.p.9.1 Description

succ(X, S) is true iff S is the successor of the non-negative integer X.

p.p.9.2 Template and modes

succ(?integer,+integer)
succ(+integer,-integer)

p.p.9.3 Errors

a) X is a variable and @@.
instantiation_error.
b) ...
NOTE — @@@@@@

p.p.9.4 Examples

?- true.
   true.

p.p.@@ succ/2

d982 2 a983 2 succ(X, S) is true iff S is the successor of the non-negative integer X. d987 2 a988 2 succ(?integer,+integer)
succ(+integer,-integer) @ 1.19 log @N290 @ text @d5 1 a5 1 N290 Prolog prologue (Working draft)N290
a554 6
c) List is a partial list and Length is the variable of the partial list. (Implementation defined)
type_error(integer, []). d611 1 a611 1
type_error(integer,Lower). d615 1 a615 1
type_error(integer,Upper). d619 1 a619 1
type_error(integer,X). d651 1 a651 1 type_error(integer,c). d654 1 a654 1 type_error(integer,1+1). d720 1 a720 1
type_error(integer,X). d724 1 a724 1
type_error(integer,S). d868 170 @ 1.18 log @*** empty log message *** @ text @d5 1 a5 1 pre-N286 Prolog prologue (Working draft)pre-N286
d487 3 a489 3 Xs = [], Ys = [a,b,c]. ; Xs = [a], Ys = [b,c]. ; Xs = [a,b], Ys = [c]. d713 2 a714 2 succ(+integer,?integer)
succ(-integer,+integer) d741 1 a741 1 is maxint. d743 2 a744 1
evaluation_error(int_overflow) a745 4
f' @@@@@@) Flag bounded is true, X is maxint and S is a variable.
evaluation_error(int_overflow) d779 4 a782 2 ?- current_prolog_flag(max_integer, Max), ( integer(Max) -> succ(Max, S) ; true ). d784 5 a788 1 | Max = unbounded. @ 1.17 log @Stefan Kral! @ text @d5 1 a5 1 post-N235 Prolog prologue (Working draft)post-N235
d73 1 a73 1 Neumerkel, 2012-09-06 d101 1 a101 1 d372 1 a372 1
further propositions:
nth/3 d419 22 a440 21 member(X, [1,2]). Succeeds, unifying X with 1. On re-execution, succeeds, unifying Y with 2. member(1, L). Succeeds, unifying L with [1|_]. On re-execution, succeeds, unifying L with [_,1|_]. On re-execution, succeeds, unifying L with [_,_,1|_]. Ad infinitum. member(X, [Y,Z|nonlist]). Succeeds, unifying X with Y. On re-execution, succeeds, unifying X with Z. member(X, nonlist). Fails. member(X, X). Undefined. [STO 7.3.3, in many implementations succeeds, or loops, or produces an error] d477 2 a478 2 append([a,b],[c,d], Xs). Succeeds, unifying Xs with [a,b,c,d]. d480 2 a481 2 append([a], nonlist, Xs). Succeeds, unifying Xs with [a|nonlist]. d483 2 a484 2 append([a], Ys, Zs). Succeeds, unifying Zs with [a|Ys]. d486 5 a490 5 append(Xs, Ys, [a,b,c]). Succeeds, unifying Xs with [], and Ys with [a,b,c]. On re-execution, succeeds, unifying Xs with [a], and Ys with [b,c]. On re-execution, succeeds, unifying Xs with [a,b], and Ys with [c]. On re-execution, succeeds, unifying Xs with [a,b,c], and Ys with []. d567 2 a568 2 length([a,b,c], Length). Succeeds, unifying Length with 3. d570 2 a571 2 length(List, 5). Succeeds, unifying List with [_,_,_,_,_]. d573 5 a577 5 length(List, Length). Succeeds, unifying List with [] and Length with 0. On re-execution, succeeds, unifying List with [_] and Length with 1. On re-execution, succeeds, unifying List with [_,_] and Length with 2. Ad infinitum. d637 6 a642 2 between(1, 2, 0). Fails. d644 2 a645 5 between(1, 2, I). Succeeds, unifying I with 1. On re-execution, succeeds, unifying I with 2. d647 1 a647 1 between(I, I, 0). d650 1 a650 1 between(1, I, 0). d653 1 a653 1 between(I, 1, 0). d656 1 a656 1 between(1, c, 0). d659 1 a659 1 between(1+1,2,I). d691 3 a693 3 select(X, [1,2], Xs). Succeeds, unifying X with 1 and Xs with [2]. On re-execution, succeeds, unifying X with 2 and Xs with [1]. d695 2 a696 2 select(X, [Y|inf], Xs). Succeeds, unifying X with Y and Xs with inf. d698 2 a699 2 select(E, Xs, Xs). STO. d740 10 d752 1 d754 1 d764 1 a764 1 succ(X, S). d767 1 a767 1 succ(X, X). d770 2 a771 2 succ(0, S). Succeeds, unifying S with 1. d773 1 a773 1 succ(1, 1+1). d776 2 a777 2 succ(X, 0). Fails. d779 1 a779 1 succ(-1, S). d781 5 d858 2 a859 2 maplist(>(3), [1, 2]). Succeeds. d861 2 a862 2 maplist(>(3), [1, 2, 3]). Fails. d864 6 a869 10 maplist(=(X), Xs). Succeeds, unifying Xs with []. On re-execution, succeeds, unifying Xs with [X]. On re-execution, succeeds, unifying Xs with [X, X]. On re-execution, succeeds, unifying Xs with [X, X, X]. Ad infinitum. @ 1.16 log @*** empty log message *** @ text @d180 1 a180 1 3 maxarity. @ 1.15 log @*** empty log message *** @ text @d113 5 a117 1 it), additions are bold green links d125 1 a125 1
7.4.2 Directives
d136 1 a136 1
7.8 Control constructs
d148 1 a148 1
7.10.2.13 Stream properties
d160 1 a160 1
7.10.3 Read-options list
d165 1 a165 1
7.10.4 Write-options list
d168 1 d171 1 a171 1
7.11.1 Flags defining integer type I
d177 1 a177 1
7.11.2 Other flags
d184 1 a184 1
7.12.2 Error classification
d197 1 a197 1
8.2 Term unification
d203 1 a203 1
8.3 Type testing
d216 1 a216 1
8.4 Term comparison
d222 1 a222 1
8.5 Term creation and decomposition
d229 1 a229 1
8.6 Arithmetic evaluation
d232 1 a232 1
8.7 Arithmetic comparison
d235 1 a235 1
8.8 Clause retrieval and information
d239 1 a239 1
8.9 Clause creation and destruction
d246 1 a246 1
8.10 All solutions
d251 1 a251 1
8.11 Stream selection and control
d262 1 a262 1
8.12 Character input/output
d267 1 a267 1
8.13 Byte input/output
d272 1 a272 1
8.14 Term input/output
d280 1 a280 1
8.15 Logic and control
d287 1 a287 1
8.16 Atomic term processing
d297 1 a297 1
8.17 Implementation defined hooks
d303 1 a303 1
9.1 The simple arithmetic functors
d311 1 a311 1
9.3 Other arithmetic functors
d328 1 a328 1
9.4 Bitwise functors
d341 1 a341 1
7.2 Module predicates
d345 1 a345 1
7.3 Clause retrieval and information
d739 2 @ 1.14 log @(updated 2013/11/29 09:16:00, after ROK's indirect comment) @ text @d669 1 a669 1 select(E, Xs, Ys). d767 14 a780 10 maplist(Cont, List1) is true iff List1 is a list and call(Cont, X1) is true for each element X1 of List1.

maplist(Cont, List1, List2) is true iff List1 and List2 are lists of same length and call(Cont, X1, X2) is true for each element X1 of List1 and each corresponding element of X2. d782 2 a783 2

maplist(Cont, List_1, List_2, ... List_n) is true iff List_1, List_2 up to List_n are d785 2 a786 2 and call(Cont, E_1_i, E_2_i, ... E_n_i) is true for each i where E_k_i is the i-th element of List_k. d792 14 a805 9 maplist(_Cont, []). maplist(Cont, [E_1|List_1]) :- call(Cont, E_1), maplist(Cont, List_1). maplist(_Cont, [], []). maplist(Cont, [E_1|List_1], [E_2|List_2]) :- call(Cont, E_1, E_2), maplist(Cont, List_1, List_2). d809 4 a812 4 maplist(_Cont, [], [], ... []). maplist(Cont, [E_1|List_1], [E_2|List_2], ... [E_n|List_n]) :- call(Cont, E_1, E_2, ... E_n), maplist(Cont, List_1, List_2, ... List_n). d820 4 a823 1 ... @ 1.13 log @Vor ROK-Kommentaren @ text @d579 1 a579 1 greater or equal Lower, and less or equal Upper. @ 1.12 log @Changes made during WG17 meeting. @ text @d5 1 a5 1 N235 Prolog prologue (Working draft)N235
d73 1 a73 1 Neumerkel, 2012-07-06 d514 1 a514 1

f) Chooses the first element Len of N being the integer 0. d522 1 a522 1 a variable, chooses the next element Len of N d548 7 @ 1.11 log @N235 @ text @d428 3 d446 3 a448 2 is a list prefix of Zs and Ys occurs in Zs immediately after the prefix Xs. d677 7 @ 1.10 log @*** empty log message *** @ text @d5 1 a5 1 Prolog prologue
A Prologue for Prolog d86 1 a86 1 predicates at all. d110 4 a113 1 link to the draft, additions are bold. d117 14 a130 1
Part 1: General core d132 1 a132 1
7.8 Control constructs:
d144 23 a166 1
7.11.1 Flags defining integer type I:
d180 11 a190 11 a) instantiation_error/0. b) type_error/2. c) domain_error/2. d) existence_error/2. e) permission_error/3. f) representation_error/1. g) evaluation_error/1. h) resource_error/1. i) syntax_error/1. j) system_error/0. k) uninstantiation_error/1. d196 1 a196 1 4 subsumes_term/2. d207 3 a209 3 9 callable/1. 10 ground/1. 11 acyclic_term/1. d213 3 a215 3 2 compare/3. 3 sort/2. 4 keysort/2. d222 1 a222 1 5 term_variables/2. d239 1 a239 1 5 retractall/1. d279 2 a280 2 4 call/2..8. 5 false/0. d303 2 a304 2 (+)/1, (div)/2. d314 8 a321 8 8 max/2. 9 min/2. 10 (^)/2. 11 asin/1. 12 acos/1. 13 atan2/2. 14 tan/1. 15 pi/0. d329 3 a331 1 6 xor/2. d333 2 a334 1
Part 2: Modules d343 1 a343 1 @ 1.9 log @*** empty log message *** @ text @d302 6 d490 1 a490 1
a) Length is a neither a variable nor an integer d652 1 a652 1
b) X is a neither a variable nor an integer d656 1 a656 1
c) S is a neither a variable nor an integer @ 1.8 log @*** empty log message *** @ text @d746 20 @ 1.7 log @*** empty log message *** @ text @d747 2 a748 1 Version control d750 3 a752 1
Validated HTML @ 1.6 log @*** empty log message *** @ text @d104 1 a104 1 link to the draft link to the draft, additions are bold. @ 1.5 log @Prior to announcement @ text @d79 1 a79 1 past, discussion on this level have prevented defining these @ 1.4 log @*** empty log message *** @ text @d494 1 a494 1

p.p.3.4 Examples

@ 1.3 log @*** empty log message *** @ text @d67 1 a67 1 Neumerkel, 2011-07-10 d89 8 a96 1

History

2011-07-10: WG17 resolution. @ 1.2 log @*** empty log message *** @ text @d94 2 a95 1 Additions d97 1 a97 2 are bold and link to the draft DTC2, since the corrigendum cannot be referred to. d106 1 a106 1 3 call/1. d109 1 a109 1 6 (;)/2 - disjunction. d111 2 a112 2 8 (;)/2 - if-then-else. 9 catch/3. d186 1 a186 1 3 retract/1. d200 1 a200 1 5 open/4, open/3. d219 1 a219 1 3 op/3. d235 2 a236 2 4 atom_chars/2. 5 atom_codes/2. d238 2 a239 2 7 number_chars/2. 8 number_codes/2. d294 1 a294 1 consisten with that used for built-in predicates (8.1). d383 1 a383 1 is a list prefix of Zs and Ys occurs d439 10 a448 1
b) If List is a list, then proceeds to ... d450 1 a450 1
c) If Length is an integer, then proceeds to ... d452 4 a455 2
d) If List is a partial list and Length is a variable ... d457 3 a459 3
Unifies List with a list of length Length with Length distinct fresh variables as elements. d461 1 a461 1 Else the goal fails. d467 1 a467 1 backtracking, continue at p.p.3.1 @@@@@@ d508 1 a508 1 greater or equal Lower, and less or equal upper. d510 2 a511 3

Procedurally, between(Lower, Upper, X) is executed as follows: d513 8 a520 9
a) Let I

between(Lower, Upper, X) is re-executable. On backtracking, continue at p.p.4.1 @@@@@@. d703 2 a704 2 and call(Cond, E_1_i, E_2_i, ... E_n_i) is true for each i where E_j_i is the i-th element of List_j. d710 11 d722 4 a727 8 The zipWith3 function takes a function which combines three elements, as well as three lists and returns a list of their point-wise combination, analogous to zipWith. @ 1.1 log @Initial revision @ text @d12 2 a13 1 background-color: white d83 2 a84 2 and concentrate on the identification and precise definition of the predicates instead. The Prolog prologue is a possibly empty file to d94 4 a97 1 Additions by Cor.2:2012 are bold d104 10 a113 10 1 true/0. 2 fail/0. 3 call/1. 4 !/0. 5 (',')/2. 6 (;)/2 - disjunction. 7 (->)/2. 8 (;)/2 - if-then-else. 9 catch/3. 10 throw/1. d116 4 a119 4 1 bounded. 2 max_integer. 3 min_integer. 4 integer_rounding_function. d122 5 a126 5 1 char_conversion. 2 debug. 3 maxarity. 4 unknown. 5 double_quotes. d129 11 a139 11 a) instantiation_error/0. b) type_error/2. c) domain_error/2. d) existence_error/2. e) permission_error/3. f) representation_error/1. g) evaluation_error/1. h) resource_error/1. i) syntax_error/1. j) system_error/0. k) uninstantiation_error/1. d142 4 a145 4 1 (=)/2. 2 unify_with_occurs_check/2. 3 (\=)/2. 4 subsumes_term/2. d148 11 a158 11 1 var/1. 2 atom/1. 3 integer/1. 4 float/1. 5 atomic/1. 6 compound/1. 7 nonvar/1. 8 number/1. 9 callable/1. 10 ground/1. 11 acyclic_term/1. d161 4 a164 4 1 (@@=<)/2, (==)/2, (\==)/2, (@@<)/2, (@@>)/2, (@@>=)/2. 2 compare/3. 3 sort/2. 4 keysort/2. d167 5 a171 5 1 functor/3. 2 arg/3. 3 (=..)/2. 4 copy_term/2 5 term_variables/2. d174 1 a174 1 1 (is)/2. d177 1 a177 1 1 (=:=)/2, (=\=)/2, (<)/2, (=<)/2, (>)/2, (>=)/2. d180 2 a181 2 1 clause/2. 2 current_predicate/1. d184 5 a188 5 1 asserta/1. 2 assertz/1. 3 retract/1. 4 abolish/1. 5 retractall/1. d191 3 a193 3 1 findall/3. 2 bagof/3. 3 setof/3. d196 9 a204 9 1 current_input/1. 2 current_output/1. 3 set_input/1. 4 set_output/1. 5 open/4, open/3. 6 close/2, close/1. 7 flush_output/1, flush_output/0. 8 stream_property/2, at_end_of_stream/0, at_end_of_stream/1. 9 set_stream_position/2. d207 3 a209 3 1 get_char/2, get_char/1, get_code/1, get_code/2. 2 peek_char/2, peek_char/1, peek_code/1, peek_code/2. 3 put_char/2, put_char/1, put_code/1, put_code/2, nl/0, nl/1. d212 3 a214 3 1 get_byte/2, get_byte/1. 2 peek_byte/2, peek_byte/1. 3 put_byte/2, put_byte/1. d217 6 a222 6 1 read_term/3, read_term/2, read/1, read/2. 2 write_term/3, write_term/2, write/1, write/2, writeq/1, writeq/2, write_canonical/1, write_canonical/2. 3 op/3. 4 current_op/3. 5 char_conversion/2. 6 current_char_conversion/2. d225 5 a229 5 1 (\+)/1. 2 once/1. 3 repeat/0. 4 call/2..8. 5 false/0. d232 8 a239 8 1 atom_length/2. 2 atom_concat/3. 3 sub_atom/5. 4 atom_chars/2. 5 atom_codes/2. 6 char_code/2. 7 number_chars/2. 8 number_codes/2. d242 4 a245 4 1 set_prolog_flag/2. 2 current_prolog_flag/2. 3 halt/0. 4 halt/1. d251 3 a253 1 ceiling/1, (+)/1, (div)/2. d256 15 a270 15 1 (**)/2. 2 sin/1. 3 cos/1. 4 atan/1. 5 exp/1. 6 log/1. 7 sqrt/1. 8 max/2. 9 min/2. 10 (^)/2. 11 asin/1. 12 acos/1. 13 atan2/2. 14 tan/1. 15 pi/0. d273 6 a278 6 1 (>>)/2. 2 (<<)/2. 3 (/\)/2. 4 (\/)/2. 5 (\)/1. 6 xor/2. d283 2 a284 2 1 current_module/1. 2 predicate_property/2. d287 1 a287 1 2 current_predicate/1. d293 3 d724 2 @