eyeprolog 1.3.78 → 1.3.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -346
- package/examples/output/portable-library-overlap.pl +1 -0
- package/examples/portable-library-overlap.pl +46 -0
- package/package.json +1 -1
- package/playground.html +2 -1
- package/src/iso.js +5 -2
- package/src/lib/assoc.pl +472 -31
- package/src/lib/charsio.pl +49 -0
- package/src/lib/clpb.pl +1975 -0
- package/src/lib/debug.pl +32 -6
- package/src/lib/dif.pl +7 -0
- package/src/lib/error.pl +2 -2
- package/src/lib/format.pl +60 -26
- package/src/lib/gensym.pl +33 -0
- package/src/lib/lists.pl +30 -0
- package/src/lib/ordsets.pl +619 -0
- package/src/lib/pio.pl +61 -0
- package/src/lib/random.pl +44 -2
- package/src/lib/reif.pl +94 -0
- package/src/lib/tabling.pl +16 -0
- package/src/lib/time.pl +26 -0
- package/src/lib/ugraphs.pl +633 -0
- package/src/lib/uuid.pl +66 -3
- package/src/lib/when.pl +103 -0
- package/src/parser.js +7 -1
- package/src/playground-worker.js +1 -1
- package/src/program.js +3 -2
- package/src/scryer-compat.js +181 -1
- package/src/solver.js +4 -0
- package/src/standard-library.js +117 -17
- package/test/run-regression.mjs +137 -14
- package/the-art-of-eyeprolog.md +113 -54
package/src/lib/debug.pl
CHANGED
|
@@ -1,17 +1,43 @@
|
|
|
1
|
-
/** Compatibility hooks
|
|
1
|
+
/** Compatibility hooks and declarative debugging.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
The three operator predicates are reused from the identical Scryer and
|
|
4
|
+
Trealla library(debug) sources. The blackboard operations are retained for
|
|
5
|
+
the constraint libraries.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
:- module(debug, [debug/1, debug/3, nodebug/1, bb_get/2, bb_b_put/2
|
|
8
|
+
:- module(debug, [debug/1, debug/3, nodebug/1, bb_get/2, bb_put/2, bb_b_put/2,
|
|
9
|
+
bb_global_get/2,
|
|
10
|
+
op(900, fx, $), op(900, fx, $-), op(950, fy, *),
|
|
11
|
+
(*)/1, ($)/1, ($-)/1]).
|
|
12
|
+
|
|
13
|
+
:- op(900, fx, $).
|
|
14
|
+
:- op(900, fx, $-).
|
|
15
|
+
:- op(950, fy, *).
|
|
16
|
+
|
|
17
|
+
:- use_module(library(format), [portray_clause/1]).
|
|
9
18
|
|
|
10
19
|
:- meta_predicate(debug(+, +, +)).
|
|
20
|
+
:- meta_predicate(*(0)).
|
|
21
|
+
:- meta_predicate($(0)).
|
|
22
|
+
:- meta_predicate($-(0)).
|
|
11
23
|
|
|
12
24
|
debug(_).
|
|
13
25
|
debug(_, _, _).
|
|
14
26
|
nodebug(_).
|
|
15
27
|
|
|
16
|
-
|
|
28
|
+
$-(Goal) :-
|
|
29
|
+
catch(Goal, Exception,
|
|
30
|
+
( portray_clause(exception:Exception:Goal), throw(Exception) )).
|
|
31
|
+
|
|
32
|
+
$(Goal) :-
|
|
33
|
+
portray_clause(call:Goal),
|
|
34
|
+
$-Goal,
|
|
35
|
+
portray_clause(exit:Goal).
|
|
36
|
+
|
|
37
|
+
*(_).
|
|
38
|
+
|
|
39
|
+
bb_get(Key, Value) :- eyeprolog__bb_get(Key, Value), !.
|
|
40
|
+
bb_get(Key, Value) :- eyeprolog__bb_global_get(Key, Value).
|
|
41
|
+
bb_global_get(Key, Value) :- eyeprolog__bb_global_get(Key, Value).
|
|
42
|
+
bb_put(Key, Value) :- eyeprolog__bb_global_put(Key, Value).
|
|
17
43
|
bb_b_put(Key, Value) :- eyeprolog__bb_b_put(Key, Value).
|
package/src/lib/dif.pl
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Scryer/Trealla-compatible module facade for EyeProlog's native dif/2. */
|
|
2
|
+
|
|
3
|
+
:- module(dif, [dif/2]).
|
|
4
|
+
|
|
5
|
+
% dif/2 is supplied by the normal EyeProlog registry. Keeping this module
|
|
6
|
+
% clause-free preserves that implementation while allowing the canonical
|
|
7
|
+
% explicit import used by library(reif) and portable source.
|
package/src/lib/error.pl
CHANGED
|
@@ -61,14 +61,14 @@ error__must_be(Type, Term) :-
|
|
|
61
61
|
; type_error(Type, Term, must_be/2)
|
|
62
62
|
).
|
|
63
63
|
|
|
64
|
-
error__proper_list([])
|
|
64
|
+
error__proper_list([]) :- !.
|
|
65
65
|
error__proper_list([_|Tail]) :- !, error__proper_list(Tail).
|
|
66
66
|
error__proper_list(Term) :-
|
|
67
67
|
( var(Term) -> instantiation_error(must_be/2)
|
|
68
68
|
; type_error(list, Term, must_be/2)
|
|
69
69
|
).
|
|
70
70
|
|
|
71
|
-
error__proper_list_of([], _)
|
|
71
|
+
error__proper_list_of([], _) :- !.
|
|
72
72
|
error__proper_list_of([Head|Tail], Type) :- !,
|
|
73
73
|
must_be(Type, Head),
|
|
74
74
|
error__proper_list_of(Tail, Type).
|
package/src/lib/format.pl
CHANGED
|
@@ -1,35 +1,69 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Formatting relations shared with the Scryer/Trealla library interface. */
|
|
2
2
|
|
|
3
|
-
:- module(format, [
|
|
3
|
+
:- module(format, [
|
|
4
|
+
format_//2,
|
|
5
|
+
format/2,
|
|
6
|
+
format/3,
|
|
7
|
+
portray_clause_//1,
|
|
8
|
+
portray_clause/1,
|
|
9
|
+
portray_clause/2,
|
|
10
|
+
listing/1
|
|
11
|
+
]).
|
|
12
|
+
|
|
13
|
+
:- use_module(library(dcgs), [seq//1]).
|
|
4
14
|
|
|
5
15
|
format(Template, Arguments) :-
|
|
6
|
-
|
|
7
|
-
|
|
16
|
+
format(user_output, Template, Arguments).
|
|
17
|
+
|
|
18
|
+
format(Stream, Template, Arguments) :-
|
|
19
|
+
phrase(format_(Template, Arguments), Chars),
|
|
20
|
+
format__put_chars(Chars, Stream).
|
|
21
|
+
|
|
22
|
+
format_(Template, Arguments) -->
|
|
23
|
+
{ format__chars(Template, Chars) },
|
|
24
|
+
format__dcg(Chars, Arguments).
|
|
8
25
|
|
|
9
26
|
format__chars(Template, Chars) :-
|
|
10
27
|
atom(Template), !,
|
|
11
28
|
atom_chars(Template, Chars).
|
|
12
29
|
format__chars(Chars, Chars).
|
|
13
30
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
format__dcg([], []) --> [].
|
|
32
|
+
format__dcg(['~','~'|Chars], Args) --> !, ['~'], format__dcg(Chars, Args).
|
|
33
|
+
format__dcg(['~',n|Chars], Args) --> !, ['\n'], format__dcg(Chars, Args).
|
|
34
|
+
format__dcg(['~',Control|Chars], [Arg|Args]) -->
|
|
35
|
+
{ format__term_control(Control),
|
|
36
|
+
eyeprolog__term_chars(Control, Arg, Text)
|
|
37
|
+
}, !,
|
|
38
|
+
seq(Text),
|
|
39
|
+
format__dcg(Chars, Args).
|
|
40
|
+
format__dcg([Char|Chars], Args) --> [Char], format__dcg(Chars, Args).
|
|
41
|
+
|
|
42
|
+
format__term_control(w).
|
|
43
|
+
format__term_control(q).
|
|
44
|
+
format__term_control(a).
|
|
45
|
+
format__term_control(d).
|
|
46
|
+
|
|
47
|
+
portray_clause_(Clause) -->
|
|
48
|
+
{ eyeprolog__term_chars(q, Clause, Chars) },
|
|
49
|
+
seq(Chars), ['.','\n'].
|
|
50
|
+
|
|
51
|
+
portray_clause(Clause) :-
|
|
52
|
+
portray_clause(user_output, Clause).
|
|
53
|
+
|
|
54
|
+
portray_clause(Stream, Clause) :-
|
|
55
|
+
phrase(portray_clause_(Clause), Chars),
|
|
56
|
+
format__put_chars(Chars, Stream).
|
|
57
|
+
|
|
58
|
+
listing(Name/Arity) :-
|
|
59
|
+
functor(Head, Name, Arity),
|
|
60
|
+
( clause(Head, Body),
|
|
61
|
+
portray_clause((Head :- Body)),
|
|
62
|
+
fail
|
|
63
|
+
; true
|
|
64
|
+
).
|
|
65
|
+
|
|
66
|
+
format__put_chars([], _).
|
|
67
|
+
format__put_chars([Char|Chars], Stream) :-
|
|
68
|
+
put_char(Stream, Char),
|
|
69
|
+
format__put_chars(Chars, Stream).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
:- module(gensym, [gensym/2,
|
|
2
|
+
reset_gensym/1]).
|
|
3
|
+
|
|
4
|
+
:- use_module(library(error)).
|
|
5
|
+
:- use_module(library(lists)).
|
|
6
|
+
:- use_module(library(iso_ext)).
|
|
7
|
+
:- use_module(library(si)).
|
|
8
|
+
:- use_module(library(debug), [bb_global_get/2, bb_put/2]).
|
|
9
|
+
|
|
10
|
+
gensym_key(Base, BaseKey) :-
|
|
11
|
+
atom_concat('gensym_', Base, BaseKey).
|
|
12
|
+
|
|
13
|
+
append_id(Base, UniqueID, Unique) :-
|
|
14
|
+
atom_chars(Base, BaseChars),
|
|
15
|
+
number_chars(UniqueID, IDChars),
|
|
16
|
+
append(BaseChars, IDChars, AtomChars),
|
|
17
|
+
atom_chars(Unique, AtomChars).
|
|
18
|
+
|
|
19
|
+
gensym(Base, Unique) :-
|
|
20
|
+
must_be(var, Unique),
|
|
21
|
+
atom_si(Base),
|
|
22
|
+
gensym_key(Base, BaseKey),
|
|
23
|
+
( bb_global_get(BaseKey, UniqueID0) -> true
|
|
24
|
+
; UniqueID0 = 0
|
|
25
|
+
),
|
|
26
|
+
UniqueID is UniqueID0 + 1,
|
|
27
|
+
append_id(Base, UniqueID, Unique),
|
|
28
|
+
bb_put(BaseKey, UniqueID).
|
|
29
|
+
|
|
30
|
+
reset_gensym(Base) :-
|
|
31
|
+
atom_si(Base),
|
|
32
|
+
gensym_key(Base, BaseKey),
|
|
33
|
+
bb_put(BaseKey, 0).
|
package/src/lib/lists.pl
CHANGED
|
@@ -24,10 +24,14 @@
|
|
|
24
24
|
foldl/4,
|
|
25
25
|
foldl/5,
|
|
26
26
|
foldl/6,
|
|
27
|
+
transpose/2,
|
|
27
28
|
sum_list/2,
|
|
29
|
+
list_max/2,
|
|
30
|
+
list_min/2,
|
|
28
31
|
min_list/2,
|
|
29
32
|
max_list/2,
|
|
30
33
|
list_to_set/2,
|
|
34
|
+
permutation/2,
|
|
31
35
|
set_nth0/4,
|
|
32
36
|
take/3,
|
|
33
37
|
drop/3,
|
|
@@ -165,14 +169,40 @@ foldl(Closure, [A|As], [B|Bs], [C|Cs], Acc0, Acc) :-
|
|
|
165
169
|
call(Closure, A, B, C, Acc0, Acc1),
|
|
166
170
|
foldl(Closure, As, Bs, Cs, Acc1, Acc).
|
|
167
171
|
|
|
172
|
+
transpose([], []).
|
|
173
|
+
transpose([[]|Rows], []) :- lists__all_empty(Rows).
|
|
174
|
+
transpose([[X|Xs]|Rows], [[X|Heads]|Columns]) :-
|
|
175
|
+
maplist(lists__list_first_rest, Rows, Heads, Tails),
|
|
176
|
+
transpose([Xs|Tails], Columns).
|
|
177
|
+
|
|
178
|
+
lists__all_empty([]).
|
|
179
|
+
lists__all_empty([[]|Rows]) :- lists__all_empty(Rows).
|
|
180
|
+
|
|
181
|
+
lists__list_first_rest([X|Xs], X, Xs).
|
|
182
|
+
|
|
168
183
|
sum_list(List, Sum) :- lists__sum_list(List, 0, Sum).
|
|
169
184
|
|
|
185
|
+
list_max([X|Xs], Max) :- foldl(lists__list_max, Xs, X, Max).
|
|
186
|
+
lists__list_max(X, Max0, Max) :- Max is max(X, Max0).
|
|
187
|
+
|
|
188
|
+
list_min([X|Xs], Min) :- foldl(lists__list_min, Xs, X, Min).
|
|
189
|
+
lists__list_min(X, Min0, Min) :- Min is min(X, Min0).
|
|
190
|
+
|
|
170
191
|
min_list([X|Xs], Min) :- lists__min_list(Xs, X, Min).
|
|
171
192
|
|
|
172
193
|
max_list([X|Xs], Max) :- lists__max_list(Xs, X, Max).
|
|
173
194
|
|
|
174
195
|
list_to_set(List, Set) :- lists__list_to_set(List, [], Set).
|
|
175
196
|
|
|
197
|
+
permutation(Xs, Ys) :-
|
|
198
|
+
same_length(Xs, Ys),
|
|
199
|
+
lists__permutation(Xs, Ys).
|
|
200
|
+
|
|
201
|
+
lists__permutation([], []).
|
|
202
|
+
lists__permutation(List, [First|Perm]) :-
|
|
203
|
+
select(First, List, Rest),
|
|
204
|
+
lists__permutation(Rest, Perm).
|
|
205
|
+
|
|
176
206
|
|
|
177
207
|
set_nth0(0, [_|Xs], X, [X|Xs]).
|
|
178
208
|
set_nth0(N, [Y|Ys], X, [Y|Zs]) :-
|