Skip to content

Commit 6983508

Browse files
authored
Merge pull request #23 from jansky/master
Added Metacircular Evaluator for Source§2 Lazy
2 parents 5509075 + 6abcde6 commit 6983508

File tree

4 files changed

+861
-0
lines changed

4 files changed

+861
-0
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

0 commit comments

Comments
 (0)