4 Once again, the lambda evaluator will make working through this
5 assignment much faster and more secure.
7 *Writing recursive functions on version 1 style lists*
9 Recall that version 1 style lists are constructed like this:
11 <textarea id="INPUT" style="border: 2px solid black; color: black; font-family: monospace; height: 3in; overflow: auto; padding: 0.5em; width: 100%;">
13 let false = \x y. y in
14 let makePair = \f s g. g f s in
15 let nil = makePair true meh in
16 let makeList = \h t. makePair false (makePair h t) in
17 let mylist = makeList 1 (makeList 2 (makeList 3 nil)) in
20 let isNil = \x. x fst in
21 let head = \l. isNil l err (l snd fst) in
22 let tail = \l. isNil l err (l snd snd) in
23 let succ = \n s z. s (n s z) in
24 let Y = \f. (\h. f (h h)) (\h. f (h h)) in
25 let length = Y (\length l. isNil l 0 (succ (length (tail l)))) in
29 <input id="PARSE" value="Normalize" type="button">
30 <input id="ETA" type="checkbox">do eta-reductions too
31 <noscript><p>You may not see it because you have JavaScript turned off. Uffff!</p></noscript>
32 <script src="/code/lambda.js"></script>
33 <script src="/code/tokens.js"></script>
34 <script src="/code/parse.js"></script>
35 <script src="/code/json2.js"></script>
39 /*jslint evil: true */
41 /*members create, error, message, name, prototype, stringify, toSource,
45 /*global JSON, make_parse, parse, source, tree */
47 // Make a new object that inherits members from an existing object.
49 if (typeof Object.create !== 'function') {
50 Object.create = function (o) {
57 // Transform a token object into an exception object and throw it.
59 Object.prototype.error = function (message, t) {
61 t.name = "SyntaxError";
68 var parse = make_parse();
71 var string, tree, expr, eta;
74 // string = JSON.stringify(tree, ['key', 'name', 'message', 'value', 'arity', 'first', 'second', 'third', 'fourth'], 4);
75 expr = tree.handler();
76 // string = JSON.stringify(expr, ['key', 'name', 'message', 'value', 'arity', 'first', 'second', 'tag', 'variable', 'left', 'right', 'bound', 'body' ], 4);
77 // string = expr.to_string() + "\n\n~~>\n\n";
79 eta = document.getElementById('ETA').checked;
80 string = string + reduce(expr, eta, false).to_string();
82 string = JSON.stringify(e, ['name', 'message', 'from', 'to', 'key',
83 'value', 'arity', 'first', 'second', 'third', 'fourth'], 4);
85 document.getElementById('OUTPUT').innerHTML = string
86 .replace(/&/g, '&')
87 .replace(/[<]/g, '<');
90 document.getElementById('PARSE').onclick = function (e) {
91 go(document.getElementById('INPUT').value);