aa
com.cliffc.aa.HM.TestHM7 Class Reference

Public Member Functions

void reset ()
 
void test00 ()
 
void test01 ()
 
void test02 ()
 
void test03 ()
 
void test04 ()
 
void test05 ()
 
void test06 ()
 
void test07 ()
 
void test08 ()
 
void test09 ()
 
void test10 ()
 
void test11 ()
 
void test12 ()
 
void test13 ()
 
void test14 ()
 
void test15 ()
 
void test16 ()
 
void test17 ()
 
void test18 ()
 
void test19 ()
 
void test20 ()
 
void test21 ()
 
void test22 ()
 
void test23 ()
 
void test24 ()
 
void test25 ()
 
void test26 ()
 
void test27 ()
 
void test28 ()
 
void test29 ()
 
void test30 ()
 
void test31 ()
 
void test32 ()
 

Detailed Description

Definition at line 9 of file TestHM7.java.

Member Function Documentation

◆ reset()

void com.cliffc.aa.HM.TestHM7.reset ( )

Definition at line 11 of file TestHM7.java.

11 { HM7.reset(); }

References com.cliffc.aa.HM.HM7.reset().

Here is the call graph for this function:

◆ test00()

void com.cliffc.aa.HM.TestHM7.test00 ( )

Definition at line 14 of file TestHM7.java.

14  {
15  HM7.hm("fred");
16  }

References com.cliffc.aa.HM.HM7.hm().

Here is the call graph for this function:

◆ test01()

void com.cliffc.aa.HM.TestHM7.test01 ( )

Definition at line 19 of file TestHM7.java.

19  {
20  T2 t = HM7.hm("3");
21  assertEquals("3",t.p());
22  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test02()

void com.cliffc.aa.HM.TestHM7.test02 ( )

Definition at line 25 of file TestHM7.java.

25  {
26  T2 t = HM7.hm("(pair1 3)");
27  assertEquals("{ A -> (pair 3 A) }",t.p());
28  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test03()

void com.cliffc.aa.HM.TestHM7.test03 ( )

Definition at line 31 of file TestHM7.java.

31  {
32  T2 t = HM7.hm("{ z -> (pair (z 3) (z \"abc\")) }");
33  assertEquals("{ { all -> A } -> (pair A A) }",t.p());
34  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test04()

void com.cliffc.aa.HM.TestHM7.test04 ( )

Definition at line 37 of file TestHM7.java.

37  {
38  T2 t = HM7.hm("fact = { n -> (if (?0 n) 1 (* n (fact (dec n))))}; fact");
39  assertEquals("{ int64 -> int64 }",t.p());
40  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test05()

void com.cliffc.aa.HM.TestHM7.test05 ( )

Definition at line 43 of file TestHM7.java.

43  {
44  // Because {y->y} is passed in, all 'y' types must agree.
45  // This unifies 3 and "abc" which results in 'all'
46  T2 t1 = HM7.hm("({ x -> (pair (x 3) (x \"abc\")) } {y->y})");
47  assertEquals("(pair all all)",t1.p());
48  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test06()

void com.cliffc.aa.HM.TestHM7.test06 ( )

Definition at line 51 of file TestHM7.java.

51  {
52  // recursive unification
53  T2 t1 = HM7.hm("{ f -> (f f) }");
54  assertEquals("{ A:{ $A -> B } -> B }",t1.p());
55  // We can argue the pretty-print should print:
56  // "A:{ $A -> B }"
57  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test07()

void com.cliffc.aa.HM.TestHM7.test07 ( )

Definition at line 60 of file TestHM7.java.

60  {
61  T2 t1 = HM7.hm("g = {f -> 5}; (g g)");
62  assertEquals("5",t1.p());
63  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test08()

void com.cliffc.aa.HM.TestHM7.test08 ( )

Definition at line 66 of file TestHM7.java.

66  {
67  // example that demonstrates generic and non-generic variables:
68  T2 t1 = HM7.hm("{ g -> f = { x -> g }; (pair (f 3) (f \"abc\"))}");
69  assertEquals("{ A -> (pair A A) }",t1.p());
70  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test09()

void com.cliffc.aa.HM.TestHM7.test09 ( )

Definition at line 73 of file TestHM7.java.

73  {
74  T2 t1 = HM7.hm("{ f g -> (f g)}");
75  assertEquals("{ { A -> B } A -> B }",t1.p());
76  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test10()

void com.cliffc.aa.HM.TestHM7.test10 ( )

Definition at line 79 of file TestHM7.java.

79  {
80  // Function composition
81  T2 t1 = HM7.hm("{ f g -> { arg -> (g (f arg))} }");
82  assertEquals("{ { A -> B } { B -> C } -> { A -> C } }",t1.p());
83  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test11()

void com.cliffc.aa.HM.TestHM7.test11 ( )

Definition at line 86 of file TestHM7.java.

86  {
87  // Stacked functions ignoring all function arguments
88  T2 t1 = HM7.hm("map = { fun -> { x -> 2 } }; ((map 3) 5)");
89  assertEquals("2",t1.p());
90  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test12()

void com.cliffc.aa.HM.TestHM7.test12 ( )

Definition at line 93 of file TestHM7.java.

93  {
94  // map takes a function and an element (collection?) and applies it (applies to collection?)
95  T2 t1 = HM7.hm("map = { fun -> { x -> (fun x)}}; { p -> 5 }");
96  assertEquals("{ A -> 5 }",t1.p());
97  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test13()

void com.cliffc.aa.HM.TestHM7.test13 ( )

Definition at line 100 of file TestHM7.java.

100  {
101  // Looking at when tvars are duplicated ("fresh" copies made).
102  // This is the "map" problem with a scalar instead of a collection.
103  // Takes a '{a->b}' and a 'a' for a couple of different prims.
104  T2 t1 = HM7.hm("map = { fun -> { x -> (fun x)}};"+
105  "(pair ((map str) 5) ((map factor) 2.3))");
106  assertEquals("(pair str (divmod flt64 flt64))",t1.p());
107  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test14()

void com.cliffc.aa.HM.TestHM7.test14 ( )

Definition at line 110 of file TestHM7.java.

110  {
111  // map takes a function and an element (collection?) and applies it (applies to collection?)
112  T2 t1 = HM7.hm("map = { fun x -> (fun x)}; (map {a->3} 5)");
113  assertEquals("3",t1.p());
114  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test15()

void com.cliffc.aa.HM.TestHM7.test15 ( )

Definition at line 117 of file TestHM7.java.

117  {
118  // map takes a function and an element (collection?) and applies it (applies to collection?)
119  T2 t1 = HM7.hm("map = { fun x -> (fun x)}; (map { a-> (pair a a)} 5)");
120  assertEquals("(pair 5 5)",t1.p());
121  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test16()

void com.cliffc.aa.HM.TestHM7.test16 ( )

Definition at line 124 of file TestHM7.java.

124  {
125  T2 t1 = HM7.hm("fcn = { p -> { a -> (pair a a) }};"+
126  "map = { fun x -> (fun x)};"+
127  "{ q -> (map (fcn q) 5)}");
128  assertEquals("{ A -> (pair 5 5) }",t1.p());
129  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test17()

void com.cliffc.aa.HM.TestHM7.test17 ( )

Definition at line 132 of file TestHM7.java.

132  {
133  // Checking behavior when using "if" to merge two functions with
134  // sufficiently different signatures, then attempting to pass them to a map
135  // & calling internally.
136  // fcn takes a predicate 'p' and returns one of two fcns.
137  // let fcn = { p -> (if p {a -> pair[a,a ]}
138  // {b -> pair[b,pair[3,b]]}) } in
139  // map takes a function and an element (collection?) and applies it (applies to collection?)
140  // let map = { fun x -> (fun x) }
141  // in { q -> ((map (fcn q)) 5) }
142  // Should return { q -> q ? [5,5] : [5,[3,5]] }
143  // Ultimately, unifies "a" with "pair[3,a]" which throws recursive unification.
144  T2 t1 = HM7.hm("fcn = {p -> (if p {a -> (pair a a)} {b -> (pair b (pair 3 b))})};"+
145  "map = { fun x -> (fun x)};"+
146  "{ q -> (map (fcn q) 5)}");
147  assertEquals("TBD",t1.p());
148  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test18()

void com.cliffc.aa.HM.TestHM7.test18 ( )

Definition at line 151 of file TestHM7.java.

151  {
152  T2 t1 = HM7.hm("cons ={x y-> {cadr -> (cadr x y)}};"+
153  "cdr ={mycons -> (mycons { p q -> q})};"+
154  "(cdr (cons 2 3))");
155  assertEquals("3",t1.p());
156  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test19()

void com.cliffc.aa.HM.TestHM7.test19 ( )

Definition at line 166 of file TestHM7.java.

166  {
167  T2 t1 = HM7.hm("cons ={x y-> {cadr -> (cadr x y)}};"+
168  "cdr ={mycons -> (mycons { p q -> q})};"+
169  "map ={fun parg -> (fun (cdr parg))};"+
170  "(pair (map str (cons 0 5)) (map isempty (cons 0 \"abc\")))"
171  );
172  assertEquals("(pair str int1)",t1.p());
173  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test20()

void com.cliffc.aa.HM.TestHM7.test20 ( )

Definition at line 177 of file TestHM7.java.

177  {
178  T2 t1 = HM7.hm("f0 = { f x -> (if (?0 x) 1 (f (f0 f (dec x)) 2))}; (f0 * 99)");
179  assertEquals("int64",t1.p());
180  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test21()

void com.cliffc.aa.HM.TestHM7.test21 ( )

Definition at line 184 of file TestHM7.java.

184  {
185  // let f0 = fn f x => (if (?0 x) 1 (* (f0 f (dec x)) 2) ) in f0 f0 99
186  // let f0 = fn f x => (if (?0 x) 1 (f (f0 f (dec x)) 2) ) in f0 * 99
187  T2 t1 = HM7.hm("f0 = { f x -> (if (?0 x) 1 (* (f0 f (dec x)) 2))}; (f0 f0 99)");
188  assertEquals("int64",t1.p());
189  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test22()

void com.cliffc.aa.HM.TestHM7.test22 ( )

Definition at line 193 of file TestHM7.java.

193  {
194  T2 t1 = HM7.hm("is_even = "+
195  " is_odd = { n -> (if (?0 n) 0 (is_even (dec n)))}; "+
196  " { n -> (if (?0 n) 1 (is_odd (dec n)))};"+
197  "(is_even 3)"
198  );
199  assertEquals("int1",t1.p());
200  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test23()

void com.cliffc.aa.HM.TestHM7.test23 ( )

Definition at line 204 of file TestHM7.java.

204  {
205  T2 t1 = HM7.hm("{ g -> fgz = "+
206  " cons = {x y -> {cadr -> (cadr x y)}};"+
207  " cdr = {mycons -> (mycons { p q -> q})};"+
208  " (cdr (cons 2 { z -> (g z) }));"+
209  " (pair (fgz 3) (fgz 5))"+
210  "}"
211  );
212  assertEquals("{ { nint8 -> A } -> (pair A A) }",t1.p());
213  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test24()

void com.cliffc.aa.HM.TestHM7.test24 ( )

Definition at line 217 of file TestHM7.java.

217  {
218  T2 t = HM7.hm("@{x=2, y=3}");
219  assertEquals("@{ x = 2, y = 3}",t.p());
220  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test25()

void com.cliffc.aa.HM.TestHM7.test25 ( )

Definition at line 224 of file TestHM7.java.

224  {
225  T2 t = HM7.hm(".x @{x =2, y =3}");
226  assertEquals("2",t.p());
227  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test26()

void com.cliffc.aa.HM.TestHM7.test26 ( )

Definition at line 230 of file TestHM7.java.

230  {
231  T2 t = HM7.hm("{ g -> @{x=g, y=g}}");
232  assertEquals("{ A -> @{ x = A, y = A} }",t.p());
233  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test27()

void com.cliffc.aa.HM.TestHM7.test27 ( )

Definition at line 236 of file TestHM7.java.

236  {
237  // Load common field 'x', ignoring mismatched fields y and z
238  T2 t = HM7.hm("{ pred -> .x (if pred @{x=2,y=3} @{x=3,z= \"abc\"}) }");
239  assertEquals("{ A -> nint8 }",t.p());
240  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test28()

void com.cliffc.aa.HM.TestHM7.test28 ( )

Definition at line 243 of file TestHM7.java.

243  {
244  // Load some fields from an unknown struct: area of a square.
245  // Since no nil-check, correct types as needing a not-nil input.
246  T2 t = HM7.hm("{ sq -> (* .x sq .y sq) }");
247  assertEquals("{ @{ y = int64, x = int64} -> int64 }",t.p());
248  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test29()

void com.cliffc.aa.HM.TestHM7.test29 ( )

Definition at line 251 of file TestHM7.java.

251  {
252  // Recursive linked-list discovery, with no end clause
253  T2 t = HM7.hm("map = { fcn lst -> @{ n1 = (map fcn .n0 lst), v1 = (fcn .v0 lst) } }; map");
254  assertEquals("{ { A -> B } C:@{ v0 = A, n0 = $C} -> D:@{ n1 = $D, v1 = B} }",t.p());
255  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test30()

void com.cliffc.aa.HM.TestHM7.test30 ( )

Definition at line 258 of file TestHM7.java.

258  {
259  // Recursive linked-list discovery, with nil
260  T2 t = HM7.hm("map = { fcn lst -> (if lst @{ n1=(map fcn .n0 lst), v1=(fcn .v0 lst) } nil) }; map");
261  assertEquals("{ { A -> B } C:@{ v0 = A, n0 = $C}? -> D:@{ n1 = $D, v1 = B}? }",t.p());
262  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test31()

void com.cliffc.aa.HM.TestHM7.test31 ( )

Definition at line 266 of file TestHM7.java.

266  {
267  // Recursive linked-list discovery, with nil
268  T2 t = HM7.hm("p0 = { x y z -> (triple x y z) };"+
269  "p1 = (triple p0 p0 p0);"+
270  "p2 = (triple p1 p1 p1);"+
271  "p3 = (triple p2 p2 p2);"+
272  "p3");
273  assertEquals("(triple (triple (triple { A B C -> (triple A B C) } { D E F -> (triple D E F) } { G H I -> (triple G H I) }) (triple { J K L -> (triple J K L) } { M N O -> (triple M N O) } { P Q R -> (triple P Q R) }) (triple { S T U -> (triple S T U) } { V21 V22 V23 -> (triple V21 V22 V23) } { V24 V25 V26 -> (triple V24 V25 V26) })) (triple (triple { V27 V28 V29 -> (triple V27 V28 V29) } { V30 V31 V32 -> (triple V30 V31 V32) } { V33 V34 V35 -> (triple V33 V34 V35) }) (triple { V36 V37 V38 -> (triple V36 V37 V38) } { V39 V40 V41 -> (triple V39 V40 V41) } { V42 V43 V44 -> (triple V42 V43 V44) }) (triple { V45 V46 V47 -> (triple V45 V46 V47) } { V48 V49 V50 -> (triple V48 V49 V50) } { V51 V52 V53 -> (triple V51 V52 V53) })) (triple (triple { V54 V55 V56 -> (triple V54 V55 V56) } { V57 V58 V59 -> (triple V57 V58 V59) } { V60 V61 V62 -> (triple V60 V61 V62) }) (triple { V63 V64 V65 -> (triple V63 V64 V65) } { V66 V67 V68 -> (triple V66 V67 V68) } { V69 V70 V71 -> (triple V69 V70 V71) }) (triple { V72 V73 V74 -> (triple V72 V73 V74) } { V75 V76 V77 -> (triple V75 V76 V77) } { V78 V79 V80 -> (triple V78 V79 V80) })))",t.p());
274  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test32()

void com.cliffc.aa.HM.TestHM7.test32 ( )

Definition at line 279 of file TestHM7.java.

279  {
280  // Recursive linked-list discovery, with nil. Unrolled once.
281  T2 t = HM7.hm("map = { lst -> (if lst @{ n1= arg= .n0 lst; (if arg @{ n1=(map .n0 arg), v1=(str .v0 arg)} nil), v1=(str .v0 lst) } nil) }; map");
282  assertEquals("{ A:@{ v0 = int64, n0 = @{ n0 = $A, v0 = int64}?}? -> B:@{ n1 = @{ n1 = $B, v1 = str}?, v1 = str}? }",t.p());
283  }

References com.cliffc.aa.HM.HM7.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

The documentation for this class was generated from the following file: