yukigo-prolog-parser 0.1.3 → 0.2.2

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/std.ts CHANGED
@@ -1,132 +1,132 @@
1
- export const stdCode = `
2
- % between(+Low, +High, ?Value)
3
- % True if Low =< Value =< High (assuming integers)
4
- between(Low, High, Low) :- Low =< High.
5
- between(Low, High, Value) :-
6
- Low < High,
7
- NextLow is Low + 1,
8
- between(NextLow, High, Value).
9
-
10
- % union(+List1, +List2, -Union)
11
- % Union of two lists without duplicates (order not preserved)
12
- union([], L, L).
13
- union([H|T], L2, Union) :-
14
- ( member(H, L2)
15
- -> union(T, L2, Union)
16
- ; Union = [H|Rest],
17
- union(T, L2, Rest)
18
- ).
19
-
20
- % intersection(+List1, +List2, -Intersection)
21
- intersection([], _, []).
22
- intersection([H|T], L2, [H|Rest]) :-
23
- member(H, L2),
24
- !,
25
- intersection(T, L2, Rest).
26
- intersection([_|T], L2, Rest) :-
27
- intersection(T, L2, Rest).
28
-
29
- % max_member(-Max, +List)
30
- max_member(Max, [Max]) :- !.
31
- max_member(Max, [H|T]) :-
32
- max_member(M, T),
33
- ( H > M
34
- -> Max = H
35
- ; Max = M
36
- ).
37
-
38
- % min_member(-Min, +List)
39
- min_member(Min, [Min]) :- !.
40
- min_member(Min, [H|T]) :-
41
- min_member(M, T),
42
- ( H < M
43
- -> Min = H
44
- ; Min = M
45
- ).
46
-
47
- % sumlist(+List, -Sum)
48
- sumlist([], 0).
49
- sumlist([H|T], Sum) :-
50
- sumlist(T, RestSum),
51
- Sum is H + RestSum.
52
-
53
- % length(?List, ?Length)
54
- length([], 0).
55
- length([_|Tail], N) :-
56
- length(Tail, M),
57
- N is M + 1.
58
-
59
- % flatten(+NestedList, -FlatList)
60
- flatten([], []).
61
- flatten([H|T], Flat) :-
62
- !,
63
- flatten(H, FlatH),
64
- flatten(T, FlatT),
65
- append(FlatH, FlatT, Flat).
66
- flatten(X, [X]).
67
-
68
- % reverse(+List, -Reversed)
69
- reverse(List, Reversed) :-
70
- reverse_acc(List, [], Reversed).
71
-
72
- reverse_acc([], Acc, Acc).
73
- reverse_acc([H|T], Acc, Reversed) :-
74
- reverse_acc(T, [H|Acc], Reversed).
75
-
76
- % list_to_set(+List, -Set)
77
- % Removes duplicates, keeps first occurrence
78
- list_to_set([], []).
79
- list_to_set([H|T], [H|Rest]) :-
80
- exclude(==(H), T, T1),
81
- list_to_set(T1, Rest).
82
-
83
- ==(H, T) :-
84
- H == T.
85
-
86
- % nth0(?Index, ?List, ?Elem)
87
- % Index starts at 0
88
- nth0(0, [H|_], H).
89
- nth0(N, [_|T], Elem) :-
90
- N > 0,
91
- N1 is N - 1,
92
- nth0(N1, T, Elem).
93
-
94
- % nth1(?Index, ?List, ?Elem)
95
- % Index starts at 1
96
- nth1(1, [H|_], H).
97
- nth1(N, [_|T], Elem) :-
98
- N > 1,
99
- N1 is N - 1,
100
- nth1(N1, T, Elem).
101
-
102
- % append/3 (needed for flatten and union)
103
- append([], L, L).
104
- append([H|T], L, [H|R]) :-
105
- append(T, L, R).
106
-
107
- % member/2 (needed for many predicates)
108
- member(H, [H|_]).
109
- member(H, [_|T]) :-
110
- member(H, T).
111
-
112
- % exclude(+Pred, +List, -Filtered)
113
- % Removes elements satisfying Pred
114
- exclude(_, [], []).
115
- exclude(Pred, [H|T], Rest) :-
116
- ( call(Pred, H)
117
- -> exclude(Pred, T, Rest)
118
- ; Rest = [H|Rest2],
119
- exclude(Pred, T, Rest2)
120
- ).
121
-
122
- % Arithmetic predicates
123
- abs(X, Y) :- Y is abs(X).
124
- round(X, Y) :- Y is round(X).
125
- sqrt(X, Y) :- Y is sqrt(X).
126
-
127
-
128
- max_list([X], X).
129
- max_list([H|T], Max) :-
130
- max_list(T, MaxTail),
131
- Max is max(H, MaxTail).
1
+ export const stdCode = `
2
+ % between(+Low, +High, ?Value)
3
+ % True if Low =< Value =< High (assuming integers)
4
+ between(Low, High, Low) :- Low =< High.
5
+ between(Low, High, Value) :-
6
+ Low < High,
7
+ NextLow is Low + 1,
8
+ between(NextLow, High, Value).
9
+
10
+ % union(+List1, +List2, -Union)
11
+ % Union of two lists without duplicates (order not preserved)
12
+ union([], L, L).
13
+ union([H|T], L2, Union) :-
14
+ ( member(H, L2)
15
+ -> union(T, L2, Union)
16
+ ; Union = [H|Rest],
17
+ union(T, L2, Rest)
18
+ ).
19
+
20
+ % intersection(+List1, +List2, -Intersection)
21
+ intersection([], _, []).
22
+ intersection([H|T], L2, [H|Rest]) :-
23
+ member(H, L2),
24
+ !,
25
+ intersection(T, L2, Rest).
26
+ intersection([_|T], L2, Rest) :-
27
+ intersection(T, L2, Rest).
28
+
29
+ % max_member(-Max, +List)
30
+ max_member(Max, [Max]) :- !.
31
+ max_member(Max, [H|T]) :-
32
+ max_member(M, T),
33
+ ( H > M
34
+ -> Max = H
35
+ ; Max = M
36
+ ).
37
+
38
+ % min_member(-Min, +List)
39
+ min_member(Min, [Min]) :- !.
40
+ min_member(Min, [H|T]) :-
41
+ min_member(M, T),
42
+ ( H < M
43
+ -> Min = H
44
+ ; Min = M
45
+ ).
46
+
47
+ % sumlist(+List, -Sum)
48
+ sumlist([], 0).
49
+ sumlist([H|T], Sum) :-
50
+ sumlist(T, RestSum),
51
+ Sum is H + RestSum.
52
+
53
+ % length(?List, ?Length)
54
+ length([], 0).
55
+ length([_|Tail], N) :-
56
+ length(Tail, M),
57
+ N is M + 1.
58
+
59
+ % flatten(+NestedList, -FlatList)
60
+ flatten([], []).
61
+ flatten([H|T], Flat) :-
62
+ !,
63
+ flatten(H, FlatH),
64
+ flatten(T, FlatT),
65
+ append(FlatH, FlatT, Flat).
66
+ flatten(X, [X]).
67
+
68
+ % reverse(+List, -Reversed)
69
+ reverse(List, Reversed) :-
70
+ reverse_acc(List, [], Reversed).
71
+
72
+ reverse_acc([], Acc, Acc).
73
+ reverse_acc([H|T], Acc, Reversed) :-
74
+ reverse_acc(T, [H|Acc], Reversed).
75
+
76
+ % list_to_set(+List, -Set)
77
+ % Removes duplicates, keeps first occurrence
78
+ list_to_set([], []).
79
+ list_to_set([H|T], [H|Rest]) :-
80
+ exclude(==(H), T, T1),
81
+ list_to_set(T1, Rest).
82
+
83
+ ==(H, T) :-
84
+ H == T.
85
+
86
+ % nth0(?Index, ?List, ?Elem)
87
+ % Index starts at 0
88
+ nth0(0, [H|_], H).
89
+ nth0(N, [_|T], Elem) :-
90
+ N > 0,
91
+ N1 is N - 1,
92
+ nth0(N1, T, Elem).
93
+
94
+ % nth1(?Index, ?List, ?Elem)
95
+ % Index starts at 1
96
+ nth1(1, [H|_], H).
97
+ nth1(N, [_|T], Elem) :-
98
+ N > 1,
99
+ N1 is N - 1,
100
+ nth1(N1, T, Elem).
101
+
102
+ % append/3 (needed for flatten and union)
103
+ append([], L, L).
104
+ append([H|T], L, [H|R]) :-
105
+ append(T, L, R).
106
+
107
+ % member/2 (needed for many predicates)
108
+ member(H, [H|_]).
109
+ member(H, [_|T]) :-
110
+ member(H, T).
111
+
112
+ % exclude(+Pred, +List, -Filtered)
113
+ % Removes elements satisfying Pred
114
+ exclude(_, [], []).
115
+ exclude(Pred, [H|T], Rest) :-
116
+ ( call(Pred, H)
117
+ -> exclude(Pred, T, Rest)
118
+ ; Rest = [H|Rest2],
119
+ exclude(Pred, T, Rest2)
120
+ ).
121
+
122
+ % Arithmetic predicates
123
+ abs(X, Y) :- Y is abs(X).
124
+ round(X, Y) :- Y is round(X).
125
+ sqrt(X, Y) :- Y is sqrt(X).
126
+
127
+
128
+ max_list([X], X).
129
+ max_list([H|T], Max) :-
130
+ max_list(T, MaxTail),
131
+ Max is max(H, MaxTail).
132
132
  `