comparison testlist.rhope @ 75:0083b2f7b3c7

Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Jul 2010 07:52:59 -0400
parents
children 004f0fc8941f
comparison
equal deleted inserted replaced
74:a844c623c7df 75:0083b2f7b3c7
1
2 Make List[list, cur, num:out]
3 {
4 If[[cur]=[num]]
5 { out <- list }
6 {
7 out <- Make List[[list]Append[cur], [cur]+[1], num]
8 }
9 }
10
11 Make List Step[list, cur index, curval, num, step:out]
12 {
13 Print["Make List Step"]
14 { Print[cur index]
15 { Print[curval]
16 {
17 If[[curval]=[num]]
18 { out <- list }
19 {
20 next <- [list]Set[cur index, curval]
21 Print[[next]Length]
22 {
23 out <- Make List Step[next, [cur index]+[step], [curval]+[1], num, step]
24 }
25 }
26 }}}
27 }
28
29 Sum[list,index,cur:out]
30 {
31 [list]Index[index]
32 {
33 out <- Sum[list,[index]+[1],[cur]+[~]]
34 }{
35 out <- cur
36 }
37 }
38
39 Calc Sum[num:out]
40 {
41 If[[[[num]/[2]]*[2]] = [num]]
42 {
43 out <- [[num]-[1]]*[[num]/[2]]
44 }{
45 out <- [[[num]-[2]]*[[[num]-[1]]/[2]]]+[[num]-[1]]
46 }
47 }
48
49 Test Size[size:out]
50 {
51 list <- Make List[List[], 0, size]
52
53 If[[[list]Length] != [size]]
54 {
55 out <- No
56 Print["Length should be:"]
57 { Print[size]
58 { Print["but was:"]
59 { Print[[list]Length] }}}
60 }{
61 tlast <- [size]-[1]
62 If[[[list]Last] != [tlast]]
63 {
64 out <- No
65 Print["Last should be:"]
66 { Print[tlast]
67 { Print["but was:"]
68 { Print[[list]Last] }}}
69 }{
70 sum <- Sum[list,0,0]
71 ssum <- Calc Sum[size]
72 If[[sum]=[ssum]]
73 {
74 out <- Yes
75 Print["Test succeeded for size:"]
76 { Print[size] }
77 }{
78 out <- No
79 Print["Sum is:"]
80 { Print[sum]
81 { Print["but should be:"]
82 { Print[ssum] }}}
83 }
84 }
85 }
86 }
87
88 Do Test[size:success,failure]
89 {
90 success <- If[Test Size[size]] {}
91 { failure <- size }
92 }
93
94 Test Next[size,step:success,failure]
95 {
96 list <- Make List Step[List[], 0, 0, size, step]
97
98 If[[[list]Length] != [size]]
99 {
100 failure <- size
101 Print["Length should be:"]
102 { Print[size]
103 { Print["but was:"]
104 { Print[[list]Length] }}}
105 }{
106 sum <- Fold[+[?], 0, list]
107 ssum <- Calc Sum[size]
108 If[[sum]=[ssum]]
109 {
110 success <- Yes
111 Print["Test succeeded for size:"]
112 { Print[size] }
113 }{
114 failure <- size
115 Print["Sum is:"]
116 { Print[sum]
117 { Print["but should be:"]
118 { Print[ssum] }}}
119 }
120 }
121 }
122
123 Test First[index:success,failure]
124 {
125 f <- [[List[]]Set[index, 0]]First
126 {
127 success <- If[[~]=[index]] {}
128 {
129 Print["First returned:"]
130 { Print[f]
131 { Print["Should have returned:"]
132 { Print[index] }}}
133 failure <- index
134 }
135 }{
136 Print["First set \"none\" output on List with 1 element at index:"]
137 { Print[index] }
138 failure <- index
139 }
140 }
141
142 Main[:out]
143 {
144 ,out <- Do Test[8i32]
145 { ,out <- Do Test[16i32]
146 { ,out <- Do Test[24i32]
147 { ,out <- Do Test[32i32]
148 {
149 Print["Basic append/retrieve tests succeeded"]
150 do ftest <- Yes
151 }}}}
152
153 Val[do ftest]
154 {
155 [List[]]First
156 {
157 Print["Calling First on empty list populated first output!"]
158 out <- 33i32
159 }{
160 Test First[0i32]
161 {
162 ,out <- Test First[7i32]
163 { ,out <- Test First[15i32]
164 { ,out <- Test First[23i32]
165 { ,out <- Test First[31i32]
166 {
167 Print["Tests of First method successful"]
168 ,out <- Test Next[33i32, 1i32]
169 { ,out <- Test Next[5i32, 2i32]
170 { ,out <- Test Next[17i32, 3i32]
171 {
172 Print["Test of Next method successful"]
173 out <- 0i32
174 }}}
175 }
176 }}}
177 }{
178 out <- 1i32
179 }
180 }
181 }
182 }
183