-
Notifications
You must be signed in to change notification settings - Fork 0
/
expand_types_with_n.pl
169 lines (132 loc) · 4.37 KB
/
expand_types_with_n.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
%% expand_types1.pl
% not the following anymore, as LPI types are simple.
% numbers(68,1,[],N),findall([N1,T3,"\n"],(member(N1,N),test_types_cases(N1,_,T,M,F,_),findall(TC,(member(T0,T),T0=[TA,TB],simplify_types(TB,[],T1),expand_types(T1,[],T2),(TB=T2->TC=y;TC=[TB,T2])),T3)),T4),writeln1(T4).
% numbers(35,1,[],N),findall([N1,T3,"\n"],(member(N1,N),test_open_types_cases(N1,_,T,M,F),findall(TC,(member(T0,T),T0=[TA,TB],simplify_types(TB,[],T1),expand_types(T1,[],T2),(TB=T2->TC=y;TC=[TB,T2])),T3)),T4),writeln1(T4).
/**
?- expand_types1([[[t, number]], [t, string], [t, number]],[],T).
T = [[[t, brackets], [[t, number]]], [t, string], [t, number]].
**/
:-include('../listprologinterpreter/curly_brackets.pl').
:-include('simplify_types_with_n.pl').
/*
expand_types(Data1,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("brackets",Dbw_brackets),
Data1=[Data2],
not(Data2=[T,_]),
expand_types1(Data2,[],Types4),
Types5=Types4,
append_list3([Types1,Types5],Types2),!.
expand_types(Data1,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("brackets",Dbw_brackets),
Data1=[[Data2|Data3]|Data41],
not([Data2|Data3]=[T,_]),
expand_types1(Data2,[],Types3),
expand_types1(Data3,Types3,Types4),
Types5=Types4,
findall(Types61,(member(Data4,Data41), expand_types1(Data4,[],Types61)),Types62),
foldr(append,Types62,Types6),
append_list3([Types1,Types5,Types6],Types2),!.
*/
expand_types(Data1,Types1,Types2) :-
expand_types1(Data1,Types1,Types2).
expand_types1([],Types,Types) :- !.
expand_types1(Data,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("number",Dbw_number),
Data=[T,Dbw_number], %number(Data),
append(Types1,[[T,Dbw_number,_]],Types2),!.
expand_types1(Data,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("string",Dbw_string),
Data=[T,Dbw_string], %string(Data),
append(Types1,[[T,Dbw_string,_]],Types2),!.
expand_types1(Data,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("atom",Dbw_atom),
Data=[T,Dbw_atom], %string(Data),
append(Types1,[[T,Dbw_atom,_]],Types2),!.
/*
expand_types1(Data1,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("brackets",Dbw_brackets),
Data1=[Data2],
not(Data2=[T,_]),
not(Data2={[T,_]}),
expand_types1(Data2,[],Types4),
Types5=[[[T,Dbw_brackets],Types4]],
append_list3([Types1,Types5],Types2),!.
*/
/*
expand_types1(Data1,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("brackets",Dbw_brackets),
Data1=[[Data2]|Data4],
expand_types1(Data2,[],Types4),
Types5=[[[T,Dbw_brackets],Types4]],
expand_types1(Data4,[],Types6),
append_list3([Types1,Types5,Types6],Types2),!.
*/
expand_types1(Data1,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("brackets",Dbw_brackets),
Data1=[[Data2|Data3]|Data41],
not([Data2|Data3]=[T,_]),
expand_types1([Data2],[],Types3),
expand_types1(Data3,Types3,Types4),
Types5=[[[T,Dbw_brackets],Types4]],
findall(Types61,(member(Data4,Data41), expand_types1([Data4],[],Types61)),Types62),
foldr(append,Types62,Types6),
append_list3([Types1,Types5,Types6],Types2),!.
expand_types1(Data1,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("list",Dbw_list),
%Data1=[Data2Data3|Data41],
%not(Data2Data3=[T,_]),
not(Data1=[T,_]),
%trace,
curly_head_taila(Data1,Data2,Data3),
%trace,
expand_types1(Data2,[],Types3),
expand_types1(Data3,Types3,Types4),
Types5=[[[T,Dbw_list],Types4]],
%trace,
%findall(Types61,(member(Data4,Data41),
%expand_types1(Data4,[],Types6),%),Types62),
%foldr(append,Types62,Types6),
append_list3([Types1,%Types5,
Types5],Types2),!.
expand_types1(Data1,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("list",Dbw_list),
Data1=[Data2Data3|Data41],
not(Data2Data3=[T,_]),
curly_head_taila(Data2Data3,Data2,Data3),
expand_types1(Data2,[],Types3),
expand_types1(Data3,Types3,Types4),
Types5=[[[T,Dbw_list],Types4]],
%trace,
findall(Types61,(member(Data4,Data41), expand_types1([Data4],[],Types61)),Types62),
foldr(append,Types62,Types6),
append_list3([Types1,Types5,
Types6],Types2),!.
expand_types1(Data,Types1,Types2) :-
get_lang_word("t",T),
%get_lang_word("string",Dbw_string),
Data=[T,A], %string(Data),
append(Types1,[[T,A]],Types2),!.
expand_types1(Data1,Types1,Types2) :-
Data1=[Data2|Data3],
expand_types1(Data2,Types1,Types3),
expand_types1(Data3,Types3,Types2),!.
%%Types2=[Types4].
%/*
append_list3(A1,B):-
append_list3(A1,[],B),!.
append_list3([],A,A):-!.
append_list3(List,A,B) :-
List=[Item|Items],
append(A,Item,C),
append_list3(Items,C,B),!.
%*/