29:- system_module( '$_setof', [(
^)
/2,
55:-
'$catch'/3
use_system_module(
'$_boot', []).
57:-
'$do_error'/2
use_system_module(
'$_errors', []).
107findall(
Template,
Generator,
Answers)
:-
108 must_be_of_type( list_or_partial_list,
Answers ),
109 '$findall'(
Template,
Generator, [],
Answers).
116findall(
Template,
Generator,
Answers,
SoFar)
:-
117 must_be_of_type( list_or_partial_list,
Answers ),
118 '$findall'(
Template,
Generator,
SoFar,
Answers).
122'$findall'(
Template,
Generator,
SoFar,
Answers)
:-
125 '$execute'(
Generator),
136'$findall_with_common_vars'(
Template,
Generator,
Answers)
:-
137 '$findall_with_common_vars'
:nb_queue(
Ref),
139 '$execute'(
Generator),
144 '$collect_with_common_vars'(
Answers,
_)
148'$collect_with_common_vars'([],
_).
149'$collect_with_common_vars'([
Key-_|Answers],
VarList)
:-
150 '$variables_in_term'(
Key,
_,
VarList),
151 '$collect_with_common_vars'(
Answers,
VarList).
174setof(
Template,
Generator,
Set)
:-
176 (
'$is_list_or_partial_list'(
Set)
->
177 '$is_list_or_partial_list'
179 '$do_error'(type_error(list,
Set), setof(
Template,
Generator,
Set))
181 '$bagof'(
Template,
Generator,
Bag),
214bagof(
Template,
Generator,
Bag)
:-
215 (
'$is_list_or_partial_list'(
Bag)
->
216 '$is_list_or_partial_list'
218 '$do_error'(type_error(list,
Bag), bagof(
Template,
Generator,
Bag))
220 '$bagof'(
Template,
Generator,
Bag).
222'$bagof'(
Template,
Generator,
Bag)
:-
223 '$free_variables_in_term'(
Template^Generator,
StrippedGenerator,
Key),
226 '$findall_with_common_vars'(
Key-Template,
StrippedGenerator,
Bags0),
227 '$keysort'(
Bags0,
Bags),
228 '$pick'(
Bags,
Key,
Bag)
230 '$findall'(
Template,
StrippedGenerator, [],
Bag0),
237'$pick'([
K-X|Bags],
Key,
Bag)
:-
238 '$parade'(
Bags,
K,
Bag1,
Bags1),
239 '$decide'(
Bags1, [
X|Bag1],
K,
Key,
Bag).
241'$parade'([
K-X|L1],
Key, [
X|B],
L)
:- '$parade'
:variant(
K,
Key),
variant,
243 '$parade'(
L1,
Key,
B,
L).
244'$parade'(
L,
_, [],
L).
253'$decide'([],
Bag,
Key0,
Key,
Bag)
:- '$decide',
255'$decide'(
_,
Bag,
Key,
Key,
Bag).
256'$decide'(
Bags,
_,
_,
Key,
Bag)
:-
257 '$pick'(
Bags,
Key,
Bag).
287all(
T,
G same X,
S)
:- all,
all(
T same X,
G,
Sx),
'$$produce'(
Sx,
S,
X).
289 '$init_db_queue'(
Ref),
290 (
catch(
G,
Error,
'$clean_findall'(
Ref,
Error) ),
292 '$db_enqueue'(
Ref,
T),
304'$$build'(
Ns,
S0,
R)
:- '$db_dequeue'(
R,
X),
'$db_dequeue',
305 '$$build2'(
Ns,
S0,
R,
X).
308'$$build2'([
X|Ns],
Hash,
R,
X)
:-
309 '$$new'(
Hash,
X),
'$$new',
310 '$$build'(
Ns,
Hash,
R).
311'$$build2'(
Ns,
Hash,
R,
_)
:-
312 '$$build'(
Ns,
Hash,
R).
314'$$new'(
V,
El)
:- var(
V),
var,
V = n(
_,
El,
_).
315'$$new'(n(
R,
El0,
L),
El)
:-
319'$$new'(=,
_,
_,
_)
:- '$$new',
'$$new'.
320'$$new'(<,
R,
_,
El)
:- '$$new'(
R,
El).
321'$$new'(>,
_,
L,
El)
:- '$$new'(
L,
El).
324'$$produce'([
T1 same X1|Tn],
S,
X)
:- '$$split'(
Tn,
T1,
X1,
S1,
S2),
326 !,
produce(
S2,
S,
X) ).
328'$$split'([],
_,
_,[],[]).
329'$$split'([
T same X|Tn],
T,
X,
S1,
S2)
:- '$$split'(
Tn,
T,
X,
S1,
S2).
330'$$split'([
T1 same X|Tn],
T,
X,[
T1|S1],
S2)
:- '$$split'(
Tn,
T,
X,
S1,
S2).
331'$$split'([
T1|Tn],
T,
X,
S1,[
T1|S2])
:- '$$split'(
Tn,
T,
X,
S1,
S2).
336catch( : Goal,+ Exception,+ Action)
findall( ?Key, +Goal, +InitialSolutions, -Solutions )
variant(? Term1, ? Term2)
nb_queue_close(+ Queue, - Head, ? Tail)
nb_queue_enqueue(+ Queue, + Element)