1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
function cons(v, ls) {
return { n : ls, v : v };
}
function callAll(ls) {
for (; ls; ls = ls.n)
ls.v();
}
function sc(v) {
return {v : v, h : null};
}
function sv(s, v) {
s.v = v;
callAll(s.h);
}
function sg(s) {
return s.v;
}
function ss(s) {
return s;
}
function sr(v) {
return {v : v, h : null};
}
function sb(x,y) {
var z = y(x.v);
var s = {v : z.v, h : null};
function reZ() {
z.h = cons(function() { s.v = z.v; callAll(s.h); }, z.h);
}
x.h = cons(function() { z = y(x.v); reZ(); s.v = z.v; callAll(s.h); }, x.h);
reZ();
return s;
}
function lastParent(pos) {
while (pos.lastChild && pos.lastChild.nodeType == 1)
pos = pos.lastChild;
return pos.parentNode;
}
var parents = null;
function pushParent(node) {
parents = cons(node, parents);
}
function popParent() {
if (parents)
parents = parents.n;
else
alert("popParent: stack underflow");
}
function curParent() {
return lastParent(parents ? parents.v : document);
}
function populate(node, html) {
node.innerHTML = html;
var scripts = node.getElementsByTagName("script");
var len = scripts.length;
for (var i = 0; i < len; ++i) {
pushParent(scripts[i].parentNode);
eval(scripts[i].textContent);
popParent();
}
}
function dyn(s) {
var x = document.createElement("span");
x.innerHTML = s.v;
curParent().appendChild(x);
s.h = cons(function() { populate(x, s.v) }, s.h);
}
function inp(t, s) {
var x = document.createElement(t);
x.value = s.v;
curParent().appendChild(x);
s.h = cons(function() { x.value = s.v }, s.h);
x.onkeyup = function() { sv(s, x.value) };
}
function eh(x) {
return x.split("&").join("&").split("<").join("<").split(">").join(">");
}
function ts(x) { return x.toString() }
function bs(b) { return (b ? "True" : "False") }
function pf() { alert("Pattern match failure") }
var closures = [];
function ca(f) {
var n = closures.length;
closures[n] = f;
return n;
}
function cr(n) {
return closures[n]();
}
|