-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.xhtml
203 lines (175 loc) · 7.86 KB
/
index.xhtml
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
<head>
<script type="text/javascript" src="./compatibility.js"></script>
<script type="text/javascript" src="./ui.js"></script>
<script type="text/javascript" src="./pp.js"></script>
<script type="text/javascript" src="./lambda.js"></script>
<script type="text/javascript" src="./app.js"></script>
<script type="text/javascript;version=1.8" src="./lambda.js"></script>
<script type="text/javascript;version=1.8" src="./app.js"></script>
<link rel="stylesheet" type="text/css" href="./default.css" />
<link rel="stylesheet" type="text/css" href="./lambda.css" />
<link rel="start" href="http://orezdnu.org/" />
<link rev="made" href="http://orezdnu.org/" />
<title>Lambda calculus in JS syntax</title>
</head>
<body onload="init('console')">
<div id="article">
<h1>Lambda calculus in JavaScript syntax</h1>
<div id="console" class="console"></div>
<ul id="strategy" class="select">
<li class="label">Evaluation strategy:</li>
</ul>
<div id="allow-eta-reduction">
<label>
<input type="checkbox" name="allow-eta" id="input-allow-eta" />
allow η-reduction
</label>
</div>
<ul id="pp" class="select">
<li class="label">Output:</li>
</ul>
<form action="." id="store"><div>
<input type="text" name="strategy" id="input-strategy" />
<input type="text" name="pp" id="input-pp" />
<input type="text" name="wait" id="input-wait" />
</div></form>
<h2>Syntax</h2>
<table id="syntax" summary="syntax">
<tr><td></td><th class="lambda">Lambda</th><th class="javascript">JavaScript</th><th class="javascript18"><a href="http://developer.mozilla.org/en/New_in_JavaScript_1.8">JavaScript 1.8</a></th></tr>
<tr><th>variable</th><td><code>x</code></td><td><code>x</code></td><td><code>x</code></td></tr>
<tr><th>abstraction</th><td><code>λx.<var>M</var></code> or <code>\x.<var>M</var></code></td><td><code>function(x){ return <var>M</var> }</code></td><td><code>function(x) <var>M</var></code></td></tr>
<tr><th>application</th><td><code>((<var>M</var>) <var>N</var>)</code></td><td><code>(<var>M</var>)(<var>N</var>)</code></td><td><code>(<var>M</var>)(<var>N</var>)</code></td></tr>
<tr><th>declaration</th><td>-</td><td><code>var a = <var>M</var>;</code></td><td><code>let a = <var>M</var>;</code></td></tr>
<tr><th>syntactic sugar</th><td><dl>
<dt><code>λx…yz.<var>M</var></code></dt>
<dd>for <code>λx…y.λz.<var>M</var></code></dd>
<dt><code>λx.<var>M</var> <var>N</var></code></dt>
<dd>for <code>λx.(<var>M</var> <var>N</var>)</code></dd>
<dt><code>(x <var>M</var>)</code></dt>
<dd>for <code>((x) <var>M</var>)</code></dd>
<dt><code>(<var>L</var> <var>M</var> <var>N</var>)</code></dt>
<dd> for <code>((<var>L</var> <var>M</var>) N)</code></dd>
</dl></td><td><dl>
<dt><code>function(x,…,y,z){ return <var>M</var> }</code></dt>
<dd>for <code>function(x,…,y){ return function(z){ return <var>M</var> } }</code></dd>
<dt><code>x(<var>M</var>)</code></dt>
<dd>for <code>(x)(<var>M</var>)</code></dd>
<dt><code><var>L</var>(<var>M</var>)(<var>N</var>)</code></dt>
<dd>for <code>(<var>L</var>(<var>M</var>))(<var>N</var>)</code></dd>
</dl></td><td><dl>
<dt><code>function(x,…,y,z) <var>M</var></code></dt>
<dd>for <code>function(x,…,y) function(z) <var>M</var></code></dd>
<dt><code>x(<var>M</var>)</code></dt>
<dd>for <code>(x)(<var>M</var>)</code></dd>
<dt><code><var>L</var>(<var>M</var>)(<var>N</var>)</code></dt>
<dd>for <code>(<var>L</var>(<var>M</var>))(<var>N</var>)</code></dd>
</dl></td></tr>
</table>
<h2>Example</h2>
<div id="example">
<dl><dt>code1</dt>
<dd>
<pre><code id="code1">(function(x){ return x })(a)</code></pre>
</dd></dl>
<p><a id="run-code1" href=".">run code1</a></p>
<dl><dt>code2</dt>
<dd>
<pre><code id="code2">(function(x,y){ return x })(a)</code></pre>
</dd></dl>
<p><a id="run-code2" href=".">run code2</a></p>
<dl><dt>code3</dt>
<dd>
<pre><code id="code3">var k = function(x,y){ return x };
k(a)(b)</code></pre>
</dd></dl>
<p><a id="run-code3" href=".">run code3</a></p>
<dl><dt>code4</dt>
<dd>
<pre><code id="code4">var s = function(x,y,z){ return x(z)(y(z)) };
var k = function(x,y){ return x };
s(k)(k)</code></pre>
</dd></dl>
<p><a id="run-code4" href=".">run code4</a></p>
<dl><dt>code5</dt>
<dd>
<pre><code id="code5">var s = function(x,y,z){ return x(z)(y(z)) };
var k = function(x,y){ return x };
s(a)(k)(c)</code></pre>
</dd></dl>
<p><a id="run-code5" href=".">run code5</a></p>
<dl><dt>code6</dt>
<dd>
<pre><code id="code6">var o = function(x){ return x(x)(c) };
o(o)</code></pre>
</dd></dl>
<p><a id="run-code6" href=".">run code6</a></p>
<dl><dt>code7 (leftmost outermost)</dt>
<dd>
<pre><code id="code7" class="leftmost-outermost">var k = function(x,y){ return x };
var o = function(x){ return x(x)(c) };
k(a)(o(o))</code></pre>
</dd></dl>
<p><a id="run-code7" href=".">run code7</a></p>
<dl><dt>code8 (call by value)</dt>
<dd>
<pre><code id="code8" class="call-by-value">var k = function(x,y){ return x };
var o = function(x){ return x(x)(c) };
k(a)(o(o))</code></pre>
</dd></dl>
<p><a id="run-code8" href=".">run code8</a></p>
<dl><dt>code9</dt>
<dd>
<pre><code id="code9">var _0 = function(s,z){ return z };
var _1 = function(s,z){ return s(z) };
var _2 = function(s,z){ return s(s(z)) };
var _3 = function(s,z){ return s(s(s(z))) };
var add = function(m,n,s,z){ return m(s)(n(s)(z)) };
add(_2)(_3)</code></pre>
</dd></dl>
<p><a id="run-code9" href=".">run code9</a></p>
<dl><dt>code10</dt>
<dd>
<pre><code id="code10">var pair = function(P,Q,x){ return x(P)(Q) }; // cons
var fst = function(p){ return p(function(x,y){ return x }) }; // car
var snd = function(p){ return p(function(x,y){ return y }) }; // cdr
var p1 = pair(pair(a)(b))(pair(c)(d));
fst(snd(p1))</code></pre>
</dd></dl>
<p><a id="run-code10" href=".">run code10</a></p>
<dl><dt>code11</dt>
<dd>
<pre><code id="code11">var t = function(x,y){ return x }; // true
var f = function(x,y){ return y }; // false
var cond = function(B,P,Q){ return B(P)(Q) }; // if-then-else
cond(t)(a)(b) // if true then a else b</code></pre>
</dd></dl>
<p><a id="run-code11" href=".">run code11</a></p>
<dl><dt>code12</dt>
<dd>
<pre><code id="code12">var Y = function(f){ return (function(x){ return f((x)(x)) })(function(x){ return f((x)(x)) }) };
var _0 = function(s,z){ return z };
var _1 = function(s,z){ return s(z) };
var _2 = function(s,z){ return s(s(z)) };
var _3 = function(s,z){ return s(s(s(z))) };
var t = function(x,y){ return x }; // true
var f = function(x,y){ return y }; // false
var if0 = function(n){ return n(function(x){ return f })(t) }; // if n equals to _0
var mul = function(m,n,s,z){ return n(m(s))(z) };
var pred = function(n,s,z){ return n(function(f,g){ return g(f(s)) })(function(x){ return z })(function(x){ return x }) };
var fact = function(r,n){ return if0(n)(_1)(mul(n)(r(pred(n)))) };
Y(fact)(_3)</code></pre>
</dd></dl>
<p><a id="run-code12" href=".">run code12</a></p>
</div>
<h2>Source code</h2>
<p>See: <a href="http://github.com/tarao/LambdaJS">http://github.com/tarao/LambdaJS</a></p>
</div>
<div id="footer">
<address>ina at kuis.kyoto-u.ac.jp</address>
</div>
</body>
</html>