aa
com.cliffc.aa.HM.TestHM6 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 ()
 

Detailed Description

Definition at line 10 of file TestHM6.java.

Member Function Documentation

◆ reset()

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

Definition at line 12 of file TestHM6.java.

12 { HM.reset(); }

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

Here is the call graph for this function:

◆ test00()

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

Definition at line 15 of file TestHM6.java.

15  {
16  HM6.hm("fred");
17  }

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

Here is the call graph for this function:

◆ test01()

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

Definition at line 20 of file TestHM6.java.

20  {
21  Syntax syn = new Con(TypeInt.con(3));
22  T2 t = HM6.hm("3");
23  assertEquals("3",t.p());
24  }

References com.cliffc.aa.type.TypeInt.con(), com.cliffc.aa.HM.HM6.hm(), and com.cliffc.aa.HM.HM7.T2.p().

Here is the call graph for this function:

◆ test02()

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

Definition at line 27 of file TestHM6.java.

27  {
28  T2 t = HM6.hm("(pair1 3)");
29  assertEquals("{ V24 -> (pair 3 V24) }",t.p());
30  }

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

Here is the call graph for this function:

◆ test03()

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

Definition at line 33 of file TestHM6.java.

33  {
34  T2 t = HM6.hm("{ z -> (pair (z 3) (z \"abc\")) }");
35  assertEquals("{ { all -> V23 } -> (pair V23 V23) }",t.p());
36  }

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

Here is the call graph for this function:

◆ test04()

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

Definition at line 39 of file TestHM6.java.

39  {
40  T2 t = HM6.hm("fact = { n -> (if/else (==0 n) 1 (* n (fact (dec n))))}; fact");
41  assertEquals("{ int64 -> int64 }",t.p());
42  }

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

Here is the call graph for this function:

◆ test05()

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

Definition at line 45 of file TestHM6.java.

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

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

Here is the call graph for this function:

◆ test06()

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

Definition at line 53 of file TestHM6.java.

53  {
54  // recursive unification
55  T2 t1 = HM6.hm("{ f -> (f f) }");
56  assertEquals("{ $25:{ $25 -> V21 } -> V21 }",t1.p());
57  // We can argue the pretty-print should print:
58  // "$26:{ $26 -> V21 }"
59  }

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

Here is the call graph for this function:

◆ test07()

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

Definition at line 62 of file TestHM6.java.

62  {
63  T2 t1 = HM6.hm("g = {f -> 5}; (g g)");
64  assertEquals("5",t1.p());
65  }

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

Here is the call graph for this function:

◆ test08()

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

Definition at line 68 of file TestHM6.java.

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

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

Here is the call graph for this function:

◆ test09()

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

Definition at line 75 of file TestHM6.java.

75  {
76  T2 t1 = HM6.hm("{ f g -> (f g)}");
77  assertEquals("{ { V20 -> V22 } V20 -> V22 }",t1.p());
78  }

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

Here is the call graph for this function:

◆ test10()

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

Definition at line 81 of file TestHM6.java.

81  {
82  // Function composition
83  T2 t1 = HM6.hm("{ f g -> { arg -> (g (f arg))} }");
84  assertEquals("{ { V19 -> V26 } { V26 -> V24 } -> { V19 -> V24 } }",t1.p());
85  }

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

Here is the call graph for this function:

◆ test11()

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

Definition at line 88 of file TestHM6.java.

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

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

Here is the call graph for this function:

◆ test12()

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

Definition at line 95 of file TestHM6.java.

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

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

Here is the call graph for this function:

◆ test13()

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

Definition at line 102 of file TestHM6.java.

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

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

Here is the call graph for this function:

◆ test14()

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

Definition at line 112 of file TestHM6.java.

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

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

Here is the call graph for this function:

◆ test15()

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

Definition at line 119 of file TestHM6.java.

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

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

Here is the call graph for this function:

◆ test16()

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

Definition at line 126 of file TestHM6.java.

126  {
127  T2 t1 = HM6.hm("fcn = { p -> { a -> (pair a a) }};"+
128  "map = { fun x -> (fun x)};"+
129  "{ q -> (map (fcn q) 5)}");
130  assertEquals("{ V23 -> (pair 5 5) }",t1.p());
131  }

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

Here is the call graph for this function:

◆ test17()

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

Definition at line 134 of file TestHM6.java.

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

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

Here is the call graph for this function:

◆ test18()

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

Definition at line 153 of file TestHM6.java.

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

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

Here is the call graph for this function:

◆ test19()

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

Definition at line 168 of file TestHM6.java.

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

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

Here is the call graph for this function:

◆ test20()

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

Definition at line 179 of file TestHM6.java.

179  {
180  T2 t1 = HM6.hm("f0 = { f x -> (if/else (==0 x) 1 (f (f0 f (dec x)) 2))}; (f0 * 99)");
181  assertEquals("int64",t1.p());
182  }

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

Here is the call graph for this function:

◆ test21()

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

Definition at line 186 of file TestHM6.java.

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

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

Here is the call graph for this function:

◆ test22()

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

Definition at line 195 of file TestHM6.java.

195  {
196  T2 t1 = HM6.hm("is_even = "+
197  " is_odd = { n -> (if/else (==0 n) 0 (is_even (dec n)))}; "+
198  " { n -> (if/else (==0 n) 1 (is_odd (dec n)))};"+
199  "(is_even 3)"
200  );
201  assertEquals("int1",t1.p());
202  }

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

Here is the call graph for this function:

◆ test23()

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

Definition at line 206 of file TestHM6.java.

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

References com.cliffc.aa.HM.HM6.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:
com.cliffc.aa.type.TypeInt
Definition: TypeInt.java:9
com.cliffc.aa.type.TypeInt.con
static TypeInt con(long con)
Definition: TypeInt.java:37