Skip to content

Commit 6abcde6

Browse files
author
Ian Duncan
committed
added tests for source chapter 2 lazy
1 parent 225b118 commit 6abcde6

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parse_and_evaluate("function f(a,b) { return a === 1 ? a : b; } f(1, head(null));");
2+
// 1
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
parse_and_eval("function at(xs, n) {\
2+
return n === 0\
3+
? head(xs)\
4+
: at(tail(xs), n-1);\
5+
}\
6+
function intsfrom(n) {\
7+
return pair(n, intsfrom(n+1));\
8+
}\
9+
function zipWith(f, xs, ys) {\
10+
return xs === null\
11+
? null\
12+
: ys === null\
13+
? null\
14+
: pair(f(head(xs), head(ys)), zipWith(f, tail(xs), tail(ys)));\
15+
}\
16+
const facs = pair(1, zipWith((x, y) => x * y, intsfrom(1), facs));\
17+
function fac(n) {\
18+
return at(facs, n);\
19+
}\
20+
fac(6);");
21+
// 720
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const list_func = "function list (x,y) {\
2+
return pair (x,pair (y,null));}";
3+
const map_func = "function map (f,xs) {\
4+
return xs === null ? xs\
5+
: pair (f(head(xs)), map (f,tail (xs)));\
6+
}";
7+
const test2 = map_func + "const a = pair(2,a); const b = map (x => x * x, a);head(tail(b));";
8+
parse_and_eval(test2);
9+
// 4

src/evaluators/source-2-lazy.js

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -826,33 +826,4 @@ function read_eval_print_loop(history) {
826826
}
827827
}
828828

829-
const test1 = "function at(xs, n) {\
830-
return n === 0\
831-
? head(xs)\
832-
: at(tail(xs), n-1);\
833-
}\
834-
function intsfrom(n) {\
835-
return pair(n, intsfrom(n+1));\
836-
}\
837-
function zipWith(f, xs, ys) {\
838-
return xs === null\
839-
? null\
840-
: ys === null\
841-
? null\
842-
: pair(f(head(xs), head(ys)), zipWith(f, tail(xs), tail(ys)));\
843-
}\
844-
const facs = pair(1, zipWith((x, y) => x * y, intsfrom(1), facs));\
845-
function fac(n) {\
846-
return at(facs, n);\
847-
}\
848-
fac(6);";
849-
//parse_and_eval(test1);
850-
851-
const list_func = "function list (x,y) {\
852-
return pair (x,pair (y,null));}";
853-
const map_func = "function map (f,xs) {\
854-
return xs === null ? xs\
855-
: pair (f(head(xs)), map (f,tail (xs)));\
856-
}";
857-
const test2 = map_func + "const a = pair(1,a); const b = map (x => x * x, a);head(tail(b));";
858-
parse_and_eval(test2);
829+

0 commit comments

Comments
 (0)