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/src/lib/debug.pl CHANGED
@@ -1,17 +1,43 @@
1
- /** Compatibility hooks for Scryer libraries.
1
+ /** Compatibility hooks and declarative debugging.
2
2
 
3
- CLP(Z) only needs the backtrackable blackboard operations; the debugging
4
- predicates are deliberately harmless no-ops unless EyeProlog grows a debug
5
- topic UI later.
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
- bb_get(Key, Value) :- eyeprolog__bb_get(Key, Value).
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
- /** Small format/2 compatibility layer covering the controls used by CLP(Z). */
1
+ /** Formatting relations shared with the Scryer/Trealla library interface. */
2
2
 
3
- :- module(format, [format/2]).
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
- format__chars(Template, Chars),
7
- format__emit(Chars, Arguments).
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
- format__emit([], []).
15
- format__emit(['~','~'|Chars], Args) :- !,
16
- put_char('~'),
17
- format__emit(Chars, Args).
18
- format__emit(['~',n|Chars], Args) :- !,
19
- nl,
20
- format__emit(Chars, Args).
21
- format__emit(['~',w|Chars], [Arg|Args]) :- !,
22
- write(Arg),
23
- format__emit(Chars, Args).
24
- format__emit(['~',q|Chars], [Arg|Args]) :- !,
25
- writeq(Arg),
26
- format__emit(Chars, Args).
27
- format__emit(['~',a|Chars], [Arg|Args]) :- !,
28
- write(Arg),
29
- format__emit(Chars, Args).
30
- format__emit(['~',d|Chars], [Arg|Args]) :- !,
31
- write(Arg),
32
- format__emit(Chars, Args).
33
- format__emit([Char|Chars], Args) :-
34
- put_char(Char),
35
- format__emit(Chars, Args).
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]) :-