1 00:00:15,314 --> 00:00:17,580 PROFESSOR: Well today we're going to learn about something 2 00:00:17,580 --> 00:00:18,410 quite amazing. 3 00:00:18,410 --> 00:00:22,950 We're going to understand what we mean by a program a little 4 00:00:22,950 --> 00:00:26,800 bit more profoundly than we have up till now. 5 00:00:26,800 --> 00:00:30,650 Up till now, we've been thinking of programs as 6 00:00:30,650 --> 00:00:32,729 describing machines. 7 00:00:32,729 --> 00:00:38,800 So for example, looking at this still store, we see here 8 00:00:38,800 --> 00:00:42,800 is a program for factorial. 9 00:00:42,800 --> 00:00:46,970 And what it is, is a character string description, if you 10 00:00:46,970 --> 00:00:49,520 will, of the wiring diagram of a 11 00:00:49,520 --> 00:00:52,230 potentially infinite machine. 12 00:00:52,230 --> 00:00:53,870 And we can look at that a little bit and 13 00:00:53,870 --> 00:00:55,130 just see the idea. 14 00:00:55,130 --> 00:00:58,950 That this is a sort of compact notation which says, if n is 15 00:00:58,950 --> 00:01:00,170 0, the result is one. 16 00:01:00,170 --> 00:01:03,800 Well here comes n coming into this machine, and if it's 0, 17 00:01:03,800 --> 00:01:06,720 then I control this switch in such a way that the switch 18 00:01:06,720 --> 00:01:09,340 allows the output to be one. 19 00:01:09,340 --> 00:01:12,970 Otherwise, it's n times factorial of n minus one. 20 00:01:12,970 --> 00:01:15,920 Well, I'm computing factorial of n minus one and multiplying 21 00:01:15,920 --> 00:01:19,350 that by n, and, in the case that it's not 0, this switch 22 00:01:19,350 --> 00:01:21,900 makes the output come from there. 23 00:01:21,900 --> 00:01:24,460 Of course, this is a machine with a potentially infinite 24 00:01:24,460 --> 00:01:27,300 number of parts, because factorial occurs within 25 00:01:27,300 --> 00:01:31,070 factorial, so we don't know how deep it has to be. 26 00:01:31,070 --> 00:01:36,480 But that's basically what our notation for programs really 27 00:01:36,480 --> 00:01:38,310 means to us at this point. 28 00:01:38,310 --> 00:01:41,810 It's a character string description, if you will, of a 29 00:01:41,810 --> 00:01:44,900 wiring diagram that could also be drawn some other way. 30 00:01:44,900 --> 00:01:47,520 And, in fact, many people have proposed to me, programming 31 00:01:47,520 --> 00:01:49,490 languages look graphical like this. 32 00:01:49,490 --> 00:01:51,500 I'm not sure I believe there are many advantages. 33 00:01:51,500 --> 00:01:54,470 The major disadvantage, of course, is that it takes up 34 00:01:54,470 --> 00:01:57,360 more space on a page, and, therefore, it's harder to pack 35 00:01:57,360 --> 00:02:01,090 into a listing or to edit very well. 36 00:02:01,090 --> 00:02:05,300 But in any case, there's something very remarkable that 37 00:02:05,300 --> 00:02:08,810 can happen in the competition world which is that you can 38 00:02:08,810 --> 00:02:10,450 have something called a universal machine. 39 00:02:10,450 --> 00:02:18,340 If we look at the second slide, what we see is a 40 00:02:18,340 --> 00:02:21,260 special machine called eval. 41 00:02:21,260 --> 00:02:23,670 There is a machine called eval, and I'm going to show it 42 00:02:23,670 --> 00:02:25,720 to you today. 43 00:02:25,720 --> 00:02:27,780 It's very simple. 44 00:02:27,780 --> 00:02:30,490 What is remarkable is that it will fit on the blackboard. 45 00:02:33,350 --> 00:02:38,310 However, eval is a machine which takes as input a 46 00:02:38,310 --> 00:02:40,450 description of another machine. 47 00:02:40,450 --> 00:02:42,620 It could take the wiring diagram of a 48 00:02:42,620 --> 00:02:46,490 factorial machine as input. 49 00:02:46,490 --> 00:02:52,020 Having done so, it becomes a simulator for the factorial 50 00:02:52,020 --> 00:02:58,910 machine such that, if you put a six in, out comes a 720. 51 00:02:58,910 --> 00:03:02,130 That's a very remarkable sort of machine. 52 00:03:02,130 --> 00:03:04,560 And the most amazing part of it is that it fits on a 53 00:03:04,560 --> 00:03:05,590 blackboard. 54 00:03:05,590 --> 00:03:10,070 By contrast, one could imagine in the analog electronics 55 00:03:10,070 --> 00:03:17,180 world a very different machine, a machine which also 56 00:03:17,180 --> 00:03:20,440 was, in some sense, universal, where you gave a circuit 57 00:03:20,440 --> 00:03:24,830 diagram as one of the inputs, for example, of this little 58 00:03:24,830 --> 00:03:28,050 low-pass filter, one-pole low-pass filter. 59 00:03:28,050 --> 00:03:30,230 And you can imagine that you could, for 60 00:03:30,230 --> 00:03:32,030 example, scan this out-- 61 00:03:32,030 --> 00:03:37,950 the scan lines are the signal that's describing what this 62 00:03:37,950 --> 00:03:40,770 machine is to simulate-- 63 00:03:40,770 --> 00:03:43,040 then the analog of that which is made out of electrical 64 00:03:43,040 --> 00:03:45,540 circuits, should configure itself into a filter that has 65 00:03:45,540 --> 00:03:47,010 the frequency response specified 66 00:03:47,010 --> 00:03:49,890 by the circuit diagram. 67 00:03:49,890 --> 00:03:52,520 That's a very hard machine to make, and, surely, there's no 68 00:03:52,520 --> 00:03:55,670 chance that I could put it on a blackboard. 69 00:03:55,670 --> 00:03:58,430 So we're going to see an amazing thing today. 70 00:03:58,430 --> 00:04:01,240 We're going to see, on the blackboard, 71 00:04:01,240 --> 00:04:02,790 the universal machine. 72 00:04:02,790 --> 00:04:06,780 And we'll see that among other things, it's extremely simple. 73 00:04:06,780 --> 00:04:10,070 Now, we're getting very close to the real spirit in the 74 00:04:10,070 --> 00:04:11,280 computer at this point. 75 00:04:11,280 --> 00:04:14,110 So I have to show a certain amount of reverence and 76 00:04:14,110 --> 00:04:16,970 respect, so I'm going to wear a suit jacket for the only 77 00:04:16,970 --> 00:04:20,470 time that you'll ever see me wear a suit jacket here. 78 00:04:20,470 --> 00:04:25,730 And I think I'm also going to put on an appropriate hat for 79 00:04:25,730 --> 00:04:26,980 the occasion. 80 00:04:28,780 --> 00:04:31,390 Now, this is a lecturer which I have to warn you-- 81 00:04:34,140 --> 00:04:37,690 let's see, normally, people under 40 and who don't have 82 00:04:37,690 --> 00:04:40,370 several children are advised to be careful. 83 00:04:40,370 --> 00:04:44,170 If they're really worried, they should leave. Because 84 00:04:44,170 --> 00:04:46,890 there's a certain amount of mysticism that will appear 85 00:04:46,890 --> 00:04:50,140 here which may be disturbing and cause 86 00:04:50,140 --> 00:04:51,820 trouble in your minds. 87 00:04:51,820 --> 00:04:57,300 Well in any case, let's see, I wish to write for you the 88 00:04:57,300 --> 00:05:02,510 evaluator for Lisp. 89 00:05:02,510 --> 00:05:05,020 Now the evaluator isn't very complicated. 90 00:05:05,020 --> 00:05:08,240 It's very much like all the programs we've seen already. 91 00:05:08,240 --> 00:05:10,860 That's the amazing part of it. 92 00:05:10,860 --> 00:05:15,370 It's going to be-- and I'm going to write it right here-- 93 00:05:15,370 --> 00:05:16,620 it's a program called eval. 94 00:05:22,900 --> 00:05:28,780 And it's a procedure of two arguments in expression of an 95 00:05:28,780 --> 00:05:30,030 environment. 96 00:05:31,860 --> 00:05:33,130 And like every interesting 97 00:05:33,130 --> 00:05:34,940 procedure, it's a case analysis. 98 00:05:40,460 --> 00:05:44,210 But before I start on this, I want to tell you some things. 99 00:05:44,210 --> 00:05:46,880 The program we're going to write on the blackboard is 100 00:05:46,880 --> 00:05:52,450 ugly, dirty, disgusting, not the way I would write this is 101 00:05:52,450 --> 00:05:54,210 a professional. 102 00:05:54,210 --> 00:05:57,940 It is written with concrete syntax, meaning you've got 103 00:05:57,940 --> 00:05:59,630 really to use lots of CARs and CDRs which is exactly what I 104 00:05:59,630 --> 00:06:02,550 told you not to do. 105 00:06:02,550 --> 00:06:07,180 That's on purpose in this case, because I want it to be 106 00:06:07,180 --> 00:06:11,010 small, compact, fit on the blackboard so you can get the 107 00:06:11,010 --> 00:06:12,420 whole thing. 108 00:06:12,420 --> 00:06:15,800 So I don't want to use long names like I normally use. 109 00:06:15,800 --> 00:06:19,580 I want to use CAR-CDR because it's short. 110 00:06:19,580 --> 00:06:20,950 Now, that's a trade-off. 111 00:06:20,950 --> 00:06:23,570 I don't want you writing programs like this. 112 00:06:23,570 --> 00:06:26,090 This is purely for an effect. 113 00:06:26,090 --> 00:06:27,530 Now, you're going to have to work a little harder to read 114 00:06:27,530 --> 00:06:29,270 it, but I'm going to try to make it clear 115 00:06:29,270 --> 00:06:31,270 as I'm writing it. 116 00:06:31,270 --> 00:06:32,395 I'm also-- 117 00:06:32,395 --> 00:06:34,960 this is a pretty much complete interpreter, but there's going 118 00:06:34,960 --> 00:06:36,290 to be room for putting in more things-- 119 00:06:36,290 --> 00:06:39,160 I'm going to leave out definition and assignment, 120 00:06:39,160 --> 00:06:45,310 just because they are not essential, for a mathematical 121 00:06:45,310 --> 00:06:51,670 reason I'll show you later and also they take up more space. 122 00:06:51,670 --> 00:06:54,170 But, in any case, what do we have to do? 123 00:06:54,170 --> 00:06:57,160 We have to do a dispatch which breaks the types of 124 00:06:57,160 --> 00:07:02,030 expressions up into particular classes. 125 00:07:02,030 --> 00:07:03,525 So that's what we're going to have here. 126 00:07:03,525 --> 00:07:05,150 Well, what expressions are there? 127 00:07:05,150 --> 00:07:06,810 Let's look at the kinds of expressions. 128 00:07:06,810 --> 00:07:10,420 We can have things like the numeral three. 129 00:07:10,420 --> 00:07:12,720 What do I want that to do? 130 00:07:12,720 --> 00:07:15,640 I can make choices, but I think right now, I want it to 131 00:07:15,640 --> 00:07:17,050 be a three. 132 00:07:17,050 --> 00:07:18,860 That's what I want. 133 00:07:18,860 --> 00:07:19,800 So that's easy enough. 134 00:07:19,800 --> 00:07:27,520 That means I want, if the thing is a number, the 135 00:07:27,520 --> 00:07:30,720 expression, that I want the expression 136 00:07:30,720 --> 00:07:31,970 itself as the answer. 137 00:07:35,420 --> 00:07:37,700 Now the next possibility is things that we 138 00:07:37,700 --> 00:07:39,390 represent as symbols. 139 00:07:39,390 --> 00:07:47,614 Examples of symbols are things like x, n, eval, number, x. 140 00:07:47,614 --> 00:07:49,630 What do I mean them to be? 141 00:07:49,630 --> 00:07:51,690 Those are things that stand for other things. 142 00:07:51,690 --> 00:07:54,770 Those are the variables of our language. 143 00:07:54,770 --> 00:07:58,540 And so I want to be able to say, for example, that x, for 144 00:07:58,540 --> 00:08:02,930 example, transforms to it's value which might be three. 145 00:08:02,930 --> 00:08:07,920 Or I might ask something like car. 146 00:08:07,920 --> 00:08:09,710 I want to have as its value-- 147 00:08:09,710 --> 00:08:17,380 be something like some procedure, which I don't know 148 00:08:17,380 --> 00:08:20,440 what is inside there, perhaps a machine language code or 149 00:08:20,440 --> 00:08:23,100 something like that. 150 00:08:23,100 --> 00:08:24,430 So, well, that's easy enough. 151 00:08:24,430 --> 00:08:27,890 I'm going to push that off on someone else. 152 00:08:27,890 --> 00:08:33,370 If something is a symbol, if the expression is a symbol, 153 00:08:33,370 --> 00:08:38,140 then I want the answer to be the result, looking up the 154 00:08:38,140 --> 00:08:40,159 expression in the environment. 155 00:08:46,480 --> 00:08:52,410 Now the environment is a dictionary which maps the 156 00:08:52,410 --> 00:08:54,060 symbol names to their values. 157 00:08:54,060 --> 00:08:56,280 And that's all it is. 158 00:08:56,280 --> 00:08:57,530 How it's done? 159 00:08:57,530 --> 00:08:59,760 Well, we'll see that later. 160 00:08:59,760 --> 00:09:01,670 It's very easy. 161 00:09:01,670 --> 00:09:03,630 It's easy to make data structures that are tables of 162 00:09:03,630 --> 00:09:04,670 various sorts. 163 00:09:04,670 --> 00:09:07,080 But it's only a table, and this is the access routine for 164 00:09:07,080 --> 00:09:10,040 some table. 165 00:09:10,040 --> 00:09:12,720 Well, the next thing, another kind of expression-- 166 00:09:12,720 --> 00:09:14,870 you have things that are described constants that are 167 00:09:14,870 --> 00:09:17,430 not numbers, like 'foo. 168 00:09:20,170 --> 00:09:22,450 Well, for my convenience, I want to syntactically 169 00:09:22,450 --> 00:09:31,520 transform that into a list structure which is, quote foo. 170 00:09:35,140 --> 00:09:39,950 A quoted object, whatever it is, is going to be actually an 171 00:09:39,950 --> 00:09:43,550 abbreviation, which is not part of the evaluator but 172 00:09:43,550 --> 00:09:46,960 happens somewhere else, an abbreviation for an expression 173 00:09:46,960 --> 00:09:48,780 that looks like this. 174 00:09:48,780 --> 00:09:52,120 This way, I can test for the type of the expression as 175 00:09:52,120 --> 00:09:55,615 being a quotation by examining the car of the expression. 176 00:09:58,460 --> 00:10:01,650 So I'm not going to worry about that in the evaluator. 177 00:10:01,650 --> 00:10:02,780 It's happening somewhere earlier in 178 00:10:02,780 --> 00:10:05,540 the reader or something. 179 00:10:05,540 --> 00:10:18,620 If the expression of the expression is quote, then what 180 00:10:18,620 --> 00:10:25,140 I want, I want quote foo to itself evaluate to foo. 181 00:10:25,140 --> 00:10:27,530 It's a constant. 182 00:10:27,530 --> 00:10:30,645 This is just a way of saying that this evaluates to itself. 183 00:10:33,150 --> 00:10:33,660 What is that? 184 00:10:33,660 --> 00:10:37,330 That's the second of the list. It's the second element of the 185 00:10:37,330 --> 00:10:41,604 list. The second element of the list is it's CADR. So I'm 186 00:10:41,604 --> 00:10:51,290 just going to write here, CADR. 187 00:10:51,290 --> 00:10:52,510 What else do we have here? 188 00:10:52,510 --> 00:10:56,040 We have lambda expressions, for example, 189 00:10:56,040 --> 00:11:04,160 lambda of x plus x y. 190 00:11:04,160 --> 00:11:05,910 Well, I going have to have some representation for the 191 00:11:05,910 --> 00:11:08,610 procedure which is the value of an expression, of a lambda 192 00:11:08,610 --> 00:11:09,600 expression. 193 00:11:09,600 --> 00:11:13,030 The procedure here is not the expression lambda x. 194 00:11:13,030 --> 00:11:16,170 That's the description of it, the textual description. 195 00:11:16,170 --> 00:11:18,800 However, what what I going to expect to see here is 196 00:11:18,800 --> 00:11:20,930 something which contains an environment as one of its 197 00:11:20,930 --> 00:11:27,360 parts if I'm implementing a lexical language. 198 00:11:27,360 --> 00:11:30,790 And so what I'd like to see is some type flags. 199 00:11:30,790 --> 00:11:33,440 I'm going to have to be able to distinguish procedures 200 00:11:33,440 --> 00:11:37,190 later, procedures which were produced by lambdas, from ones 201 00:11:37,190 --> 00:11:39,060 that may be primitive. 202 00:11:39,060 --> 00:11:42,440 And so I'm going to have some flag, which I'll just 203 00:11:42,440 --> 00:11:44,935 arbitrarily call closure, just for historical reasons. 204 00:11:47,760 --> 00:11:49,920 Now, to say what parts of this are important. 205 00:11:49,920 --> 00:11:51,970 I'm going to need to know the bound variable 206 00:11:51,970 --> 00:11:54,220 list and the body. 207 00:11:54,220 --> 00:12:00,870 Well, that's the CDR of this, so it's going to be x and plus 208 00:12:00,870 --> 00:12:03,795 x y and some environment. 209 00:12:08,170 --> 00:12:13,980 Now this is not something that users should ever see, this is 210 00:12:13,980 --> 00:12:16,680 purely a representation, internally, 211 00:12:16,680 --> 00:12:18,520 for a procedure object. 212 00:12:18,520 --> 00:12:22,010 It contains a bound variable list, a body, and an 213 00:12:22,010 --> 00:12:26,340 environment, and some type tag saying, I am a procedure. 214 00:12:26,340 --> 00:12:28,080 I'm going to make one now. 215 00:12:28,080 --> 00:12:43,720 So if the CAR of the expression is quote lambda, 216 00:12:43,720 --> 00:12:45,970 then what I'm going to put here is-- 217 00:12:45,970 --> 00:12:58,860 I'm going to make a list of closure, the CDR of the 218 00:12:58,860 --> 00:13:07,520 procedure description was everything except the lambda, 219 00:13:07,520 --> 00:13:10,250 and the current environment. 220 00:13:10,250 --> 00:13:14,470 This implements the rule for environments in the 221 00:13:14,470 --> 00:13:15,190 environment model. 222 00:13:15,190 --> 00:13:17,980 It has to do with construction of procedures from lambda 223 00:13:17,980 --> 00:13:19,210 expressions. 224 00:13:19,210 --> 00:13:22,180 The environment that was around at the time the 225 00:13:22,180 --> 00:13:25,940 evaluator encountered the lambda expression is the 226 00:13:25,940 --> 00:13:30,990 environment where the procedure resulting interprets 227 00:13:30,990 --> 00:13:32,240 it's free variables. 228 00:13:34,720 --> 00:13:35,920 So that's part of that. 229 00:13:35,920 --> 00:13:38,120 And so we have to capture that environment as part of the 230 00:13:38,120 --> 00:13:39,210 procedure object. 231 00:13:39,210 --> 00:13:41,750 And we'll see how that gets used later. 232 00:13:41,750 --> 00:13:45,140 There are also conditional expressions of things like 233 00:13:45,140 --> 00:13:54,520 COND of say, p one, e one, p two, e two. 234 00:13:54,520 --> 00:13:57,670 Where this is a predicate, a predicate is a thing that is 235 00:13:57,670 --> 00:14:00,930 either true or false, and the expression to be evaluated if 236 00:14:00,930 --> 00:14:03,480 the predicate is true. 237 00:14:03,480 --> 00:14:05,516 A set of clauses, if you will, that's the 238 00:14:05,516 --> 00:14:06,790 name for such a thing. 239 00:14:06,790 --> 00:14:09,360 So I'm going put that somewhere else. 240 00:14:09,360 --> 00:14:12,420 We're going to worry about that in another piece of code. 241 00:14:12,420 --> 00:14:13,670 So EQ-- 242 00:14:15,900 --> 00:14:24,710 if the CAR of the expression is COND, then I'm going to do 243 00:14:24,710 --> 00:14:30,800 nothing more than evaluate the COND, the CDR of the 244 00:14:30,800 --> 00:14:32,050 expression. 245 00:14:34,080 --> 00:14:38,380 That's all the clauses in the environment that I'm given. 246 00:14:41,430 --> 00:14:46,480 Well, there's one more case, arbitrary thing like the sum 247 00:14:46,480 --> 00:14:53,380 of x and three, where this is an operator applied to 248 00:14:53,380 --> 00:14:56,590 operands, and there's nothing special about it. 249 00:14:56,590 --> 00:14:59,850 It's not one of the special cases, the special forms. 250 00:14:59,850 --> 00:15:09,650 These are the special forms. 251 00:15:09,650 --> 00:15:12,480 And if I were writing here a professional program, again, I 252 00:15:12,480 --> 00:15:14,370 would somehow make this data directed. 253 00:15:14,370 --> 00:15:16,690 So there wouldn't be a sequence of conditionals here, 254 00:15:16,690 --> 00:15:20,290 there'd be a dispatch on some bits if I were trying to do 255 00:15:20,290 --> 00:15:22,360 this in a more professional way. 256 00:15:22,360 --> 00:15:25,750 So that, in fact, I can add to the thing without changing my 257 00:15:25,750 --> 00:15:26,710 program much. 258 00:15:26,710 --> 00:15:29,850 So, for example, they would run fast, but I'm not worried 259 00:15:29,850 --> 00:15:31,280 about that. 260 00:15:31,280 --> 00:15:34,890 Here we're trying to look at this in its entirety. 261 00:15:34,890 --> 00:15:37,360 So it's else. 262 00:15:37,360 --> 00:15:38,560 Well, what do we do? 263 00:15:38,560 --> 00:15:40,965 In this case, I have to somehow do an addition. 264 00:15:44,350 --> 00:15:46,565 Well, I could find out what the plus is. 265 00:15:46,565 --> 00:15:50,550 I have to find out what the x and the three are. 266 00:15:50,550 --> 00:15:53,330 And then I have to apply the result of finding what the 267 00:15:53,330 --> 00:15:56,360 plus is to the result of finding out what the x 268 00:15:56,360 --> 00:15:58,020 and the three are. 269 00:15:58,020 --> 00:15:59,830 We'll have a name for that. 270 00:15:59,830 --> 00:16:11,280 So I'm going to apply the result of evaluating the CAR 271 00:16:11,280 --> 00:16:13,270 of the expression-- 272 00:16:13,270 --> 00:16:17,210 the car of the expression is the operator-- 273 00:16:17,210 --> 00:16:20,480 in the environment given. 274 00:16:20,480 --> 00:16:24,050 So evaluating the operator gets me the procedure. 275 00:16:24,050 --> 00:16:27,290 Now I have to evaluate all the operands to get the arguments. 276 00:16:27,290 --> 00:16:34,710 I'll call that EVLIST, the CDR of the operands, of the 277 00:16:34,710 --> 00:16:38,835 expression, with respect to the environment. 278 00:16:41,940 --> 00:16:43,290 EVLIST will come up later-- 279 00:16:43,290 --> 00:16:48,070 EVLIST, apply, COND pair, COND, lambda, define. 280 00:16:50,900 --> 00:16:53,630 So that what you are seeing here now is pretty much all 281 00:16:53,630 --> 00:16:56,590 there is in the evaluator itself. 282 00:16:56,590 --> 00:17:01,370 It's the case dispatch on the type of the expression with 283 00:17:01,370 --> 00:17:07,470 the default being a general application or a combination. 284 00:17:17,520 --> 00:17:20,089 Now there is lots of things we haven't defined yet. 285 00:17:20,089 --> 00:17:21,780 Let's just look at them and see what they are. 286 00:17:21,780 --> 00:17:25,480 We're going to have to do this later, evcond. 287 00:17:25,480 --> 00:17:27,579 We have to write apply. 288 00:17:27,579 --> 00:17:29,120 We're going to have to write EVLIST. We're 289 00:17:29,120 --> 00:17:31,790 going to write LOOKUP. 290 00:17:31,790 --> 00:17:33,430 I think that's everything, isn't there? 291 00:17:33,430 --> 00:17:35,860 Everything else is something which is simple, or primitive, 292 00:17:35,860 --> 00:17:38,570 or something like that. 293 00:17:38,570 --> 00:17:42,360 And, of course, we could many more special forms here, but 294 00:17:42,360 --> 00:17:44,450 that would be a bad idea in general in a language. 295 00:17:44,450 --> 00:17:46,730 You make a language very complicated by putting a lot 296 00:17:46,730 --> 00:17:47,690 of things in there. 297 00:17:47,690 --> 00:17:49,830 The number of reserve words that should exist in a 298 00:17:49,830 --> 00:17:52,540 language should be no more than a person could remember 299 00:17:52,540 --> 00:17:54,010 on his fingers and toes. 300 00:17:54,010 --> 00:17:56,820 And I get very upset with languages which have hundreds 301 00:17:56,820 --> 00:17:59,410 of reserve words. 302 00:17:59,410 --> 00:18:00,710 But that's where the reserve words go. 303 00:18:04,750 --> 00:18:06,430 Well, now let's get to the next part of 304 00:18:06,430 --> 00:18:09,640 this, the kernel, apply. 305 00:18:09,640 --> 00:18:11,590 What else is this doing? 306 00:18:11,590 --> 00:18:17,020 Well, apply's job is to take a procedure and apply it to its 307 00:18:17,020 --> 00:18:19,500 arguments after both have been evaluated to come up with a 308 00:18:19,500 --> 00:18:22,560 procedure and the arguments rather the operator symbols 309 00:18:22,560 --> 00:18:25,360 and the operand symbols, whatever they are-- 310 00:18:25,360 --> 00:18:26,610 symbolic expressions. 311 00:18:33,270 --> 00:18:40,810 So we will define apply to be a procedure of two arguments, 312 00:18:40,810 --> 00:18:43,280 a procedure and arguments. 313 00:18:47,110 --> 00:18:48,080 And what does it do? 314 00:18:48,080 --> 00:18:49,720 It does nothing very complicated. 315 00:18:49,720 --> 00:18:50,970 It's got two cases. 316 00:18:53,580 --> 00:18:55,095 Either the procedure is primitive-- 317 00:19:02,970 --> 00:19:06,930 And I don't know exactly how that is done. 318 00:19:06,930 --> 00:19:10,930 It's possible there's some type information just like we 319 00:19:10,930 --> 00:19:14,110 made closure for, here, being the description of the type of 320 00:19:14,110 --> 00:19:16,810 a compound thing-- 321 00:19:16,810 --> 00:19:18,550 probably so. 322 00:19:18,550 --> 00:19:21,360 But it is not essential how that works, and, in fact, it 323 00:19:21,360 --> 00:19:24,140 turns out, as you probably know or have deduced, that you 324 00:19:24,140 --> 00:19:27,350 don't need any primitives anyway. 325 00:19:27,350 --> 00:19:30,732 You can compute anything without them because some of 326 00:19:30,732 --> 00:19:33,190 the lambda that I've been playing with. 327 00:19:33,190 --> 00:19:34,750 But it's nice to have them. 328 00:19:34,750 --> 00:19:36,630 So here we're going to do some magic which I'm 329 00:19:36,630 --> 00:19:38,060 not going to explain. 330 00:19:38,060 --> 00:19:42,860 Go to machine language, apply primop. 331 00:19:42,860 --> 00:19:44,850 Here's how it adds. 332 00:19:44,850 --> 00:19:46,100 Execute an add instruction. 333 00:19:50,360 --> 00:19:52,840 However, the interesting part of a language is the glue by 334 00:19:52,840 --> 00:19:54,940 which the predicates are glued together. 335 00:19:54,940 --> 00:19:56,910 So let's look at that. 336 00:19:56,910 --> 00:20:01,210 Well, the other possibility is that this is a compound made 337 00:20:01,210 --> 00:20:05,140 up by executing a lambda expression, this 338 00:20:05,140 --> 00:20:07,620 is a compound procedure. 339 00:20:07,620 --> 00:20:10,110 Well, we'll check its type. 340 00:20:10,110 --> 00:20:23,010 If it is closure, if it's one of those, then I have to do an 341 00:20:23,010 --> 00:20:24,500 eval of the body. 342 00:20:24,500 --> 00:20:28,960 The way I do this, the way I deal with this at all, is the 343 00:20:28,960 --> 00:20:31,210 way I evaluate the application of a procedure to its 344 00:20:31,210 --> 00:20:34,400 arguments, is by evaluating the body of the procedure in 345 00:20:34,400 --> 00:20:37,050 the environment resulting from extending the environment of 346 00:20:37,050 --> 00:20:39,670 the procedure with the bindings of the formal 347 00:20:39,670 --> 00:20:43,010 parameters of the procedure to the arguments that 348 00:20:43,010 --> 00:20:44,260 were passed to it. 349 00:20:47,030 --> 00:20:48,280 That was a long sentence. 350 00:20:51,130 --> 00:20:52,822 Well that's easy enough. 351 00:20:52,822 --> 00:20:56,214 Now here's going to be a lot of CAR-CDRing. 352 00:20:56,214 --> 00:20:59,400 I have to get the body of the procedure. 353 00:20:59,400 --> 00:21:02,960 Where's the body of the procedure in here? 354 00:21:02,960 --> 00:21:05,490 Well here's the CAR, here's the CDR is the 355 00:21:05,490 --> 00:21:06,130 whole rest of this. 356 00:21:06,130 --> 00:21:09,130 So here's the CADR. And so I see, what I have here is the 357 00:21:09,130 --> 00:21:11,430 body is the second element of the second 358 00:21:11,430 --> 00:21:13,200 element of the procedure. 359 00:21:13,200 --> 00:21:19,170 So it's the CADR of the CADR or the CADADR. 360 00:21:19,170 --> 00:21:27,495 It's the C-A-D-A-D-R, CADADR of the procedure. 361 00:21:30,260 --> 00:21:35,170 To evaluate the body in the result of binding that's 362 00:21:35,170 --> 00:21:39,080 making up more environment, well I need the formal 363 00:21:39,080 --> 00:21:43,500 parameters of the of the procedure, what is that? 364 00:21:43,500 --> 00:21:48,780 That's the CAR of the CDR. It's horrible isn't it? 365 00:21:52,440 --> 00:21:55,440 --of the procedure. 366 00:21:55,440 --> 00:22:00,370 Bind that to the arguments that were passed in the 367 00:22:00,370 --> 00:22:04,540 environment, which is passed also as part of the procedure. 368 00:22:04,540 --> 00:22:09,670 Well, that's the CAR of the CDR of the CDR of this, 369 00:22:09,670 --> 00:22:16,315 CADADR, of the procedure. 370 00:22:20,290 --> 00:22:26,490 Bind, eval, pair, COND, lamda, define-- 371 00:22:26,490 --> 00:22:29,370 Now, of course, if I were being really a neat character, 372 00:22:29,370 --> 00:22:33,490 and I was being very careful, I would actually put an extra 373 00:22:33,490 --> 00:22:36,540 case here for checking for certain errors like, did you 374 00:22:36,540 --> 00:22:39,000 try to apply one to an argument? 375 00:22:39,000 --> 00:22:42,570 You get a undefined procedure type. 376 00:22:42,570 --> 00:22:45,500 So I may as well do that anyway. 377 00:22:45,500 --> 00:22:57,610 --else, some sort of error, like that. 378 00:22:57,610 --> 00:23:02,620 Now, of course, again, in some sort of more real system, 379 00:23:02,620 --> 00:23:06,770 written for professional reasons, this would be written 380 00:23:06,770 --> 00:23:10,750 with a case analysis done by some sort of dispatch. 381 00:23:10,750 --> 00:23:13,250 Over here, I would probably have other cases like, is this 382 00:23:13,250 --> 00:23:16,220 compiled code? 383 00:23:16,220 --> 00:23:17,020 It's very important. 384 00:23:17,020 --> 00:23:19,530 I might have distinguished the kind of code that's produced 385 00:23:19,530 --> 00:23:23,150 by a directly evaluating a lambda in interpretation from 386 00:23:23,150 --> 00:23:25,190 code that was produced by somebody's compiler or 387 00:23:25,190 --> 00:23:25,880 something like that. 388 00:23:25,880 --> 00:23:27,230 And we'll talk about that later. 389 00:23:27,230 --> 00:23:28,710 Or is this a piece Fortran program I have 390 00:23:28,710 --> 00:23:30,510 to go off and execute. 391 00:23:30,510 --> 00:23:31,820 It's a perfectly possible thing, at this 392 00:23:31,820 --> 00:23:32,920 point, to do that. 393 00:23:32,920 --> 00:23:36,070 In fact, in this concrete syntax evaluator I'm writing 394 00:23:36,070 --> 00:23:42,600 here, there's an assumption built in that this is Lisp, 395 00:23:42,600 --> 00:23:44,360 because I'm using CARs and CDRs. 396 00:23:44,360 --> 00:23:46,750 CAR means the operator, and CDR means the operand. 397 00:23:46,750 --> 00:23:50,500 In the text, there is an abstract syntax evaluator for 398 00:23:50,500 --> 00:23:52,160 which these could be-- 399 00:23:52,160 --> 00:23:54,310 these are given abstract names like operator, and operand, 400 00:23:54,310 --> 00:23:56,160 and all these other things are like that. 401 00:23:56,160 --> 00:24:00,320 And, in that case, you could reprogram it to be ALGOL with 402 00:24:00,320 --> 00:24:01,570 no problem. 403 00:24:03,760 --> 00:24:07,410 Well, here we have added another couple of things that 404 00:24:07,410 --> 00:24:08,660 we haven't defined. 405 00:24:10,810 --> 00:24:13,800 I don't think I'll worry about these at all, however, this 406 00:24:13,800 --> 00:24:15,050 one will be interesting later. 407 00:24:17,930 --> 00:24:20,550 Let's just proceed through this and get it done. 408 00:24:20,550 --> 00:24:21,810 There's only two more blackboards so it 409 00:24:21,810 --> 00:24:23,060 can't be very long. 410 00:24:27,056 --> 00:24:30,070 It's carefully tailored to exactly fit. 411 00:24:30,070 --> 00:24:30,980 Well, what do we have left? 412 00:24:30,980 --> 00:24:33,730 We have to define EVLIST, which is over here. 413 00:24:33,730 --> 00:24:40,620 And EVLIST is nothing more than a map down a bunch of 414 00:24:40,620 --> 00:24:44,240 operands producing arguments. 415 00:24:44,240 --> 00:24:45,820 But I'm going to write it out. 416 00:24:45,820 --> 00:24:47,445 And one of the reasons I'm going to write this out is for 417 00:24:47,445 --> 00:24:51,820 a mystical reason, which is I want to make this evaluator so 418 00:24:51,820 --> 00:24:53,610 simple that it can understand itself. 419 00:24:56,450 --> 00:25:00,230 I'm going to really worry about that a little bit. 420 00:25:00,230 --> 00:25:02,850 So let's write it out completely. 421 00:25:02,850 --> 00:25:04,890 See, I don't want to worry about whether or not the thing 422 00:25:04,890 --> 00:25:06,080 can pass functional arguments. 423 00:25:06,080 --> 00:25:08,980 The value evaluator is not going to use them. 424 00:25:08,980 --> 00:25:10,880 The evaluator is not going to produce functional values. 425 00:25:10,880 --> 00:25:12,310 So even if there were a different, alternative 426 00:25:12,310 --> 00:25:16,510 language that were very close to this, this evaluates a 427 00:25:16,510 --> 00:25:19,830 complex language like Scheme which does allow procedural 428 00:25:19,830 --> 00:25:24,070 arguments, procedural values, and procedural data. 429 00:25:24,070 --> 00:25:28,100 But even if I were evaluating ALGOL, which doesn't allow 430 00:25:28,100 --> 00:25:31,580 procedural values, I could use this evaluator. 431 00:25:31,580 --> 00:25:32,870 And this evaluator is not making any 432 00:25:32,870 --> 00:25:34,050 assumptions about that. 433 00:25:34,050 --> 00:25:36,580 And, in fact, if this value were to be restricted to not 434 00:25:36,580 --> 00:25:37,700 being able to that, it wouldn't matter, because it 435 00:25:37,700 --> 00:25:40,640 doesn't use any of those clever things. 436 00:25:40,640 --> 00:25:44,070 So that's why I'm arranging this to be super simple. 437 00:25:44,070 --> 00:25:45,970 This is sort of the kernel of all possible language 438 00:25:45,970 --> 00:25:47,810 evaluators. 439 00:25:47,810 --> 00:25:49,420 How about that? 440 00:25:49,420 --> 00:25:50,670 Evlist-- 441 00:25:52,525 --> 00:25:53,820 well, what is it? 442 00:25:53,820 --> 00:25:56,300 It's the procedure of two arguments, l and an 443 00:25:56,300 --> 00:26:06,260 environment, where l is a list such that if the list of 444 00:26:06,260 --> 00:26:12,380 arguments is the empty list, then the result is the empty 445 00:26:12,380 --> 00:26:21,480 list. Otherwise, I want to cons up the result of 446 00:26:21,480 --> 00:26:31,880 evaluating the CAR of the list of operands in the 447 00:26:31,880 --> 00:26:33,260 environment. 448 00:26:33,260 --> 00:26:36,360 So I want the first operand evaluated, and I'm going to 449 00:26:36,360 --> 00:26:40,735 make a list of the results by CONSing that onto the result 450 00:26:40,735 --> 00:26:48,880 of this EVLISTing as a CDR recursion, the CDR of the list 451 00:26:48,880 --> 00:26:50,130 relative to the same environment. 452 00:26:53,350 --> 00:26:57,960 Evlist, cons, else, COND, lambda, define-- 453 00:27:00,950 --> 00:27:03,620 And I have one more that I want to put on the blackboard. 454 00:27:03,620 --> 00:27:05,470 It's the essence of this whole thing. 455 00:27:05,470 --> 00:27:08,130 And there's some sort of next layer down. 456 00:27:14,540 --> 00:27:15,770 Conditionals-- 457 00:27:15,770 --> 00:27:17,500 conditionals are the only thing left that are sort of 458 00:27:17,500 --> 00:27:18,880 substantial. 459 00:27:18,880 --> 00:27:22,320 Then below that, we have to worry about things like lookup 460 00:27:22,320 --> 00:27:25,530 and bind, and we'll look at that in a second. 461 00:27:25,530 --> 00:27:29,030 But of the substantial stuff at this level of detail, next 462 00:27:29,030 --> 00:27:31,600 important thing is how you deal with conditionals. 463 00:27:31,600 --> 00:27:33,330 Well, how do we have a conditional thing? 464 00:27:37,670 --> 00:27:44,720 It's a procedure of a set of clauses and an environment. 465 00:27:47,340 --> 00:27:49,820 And what does it do? 466 00:27:49,820 --> 00:28:03,310 It says, if I've no more clauses, well, I have to give 467 00:28:03,310 --> 00:28:04,520 this a value. 468 00:28:04,520 --> 00:28:06,540 It could be that it was an error. 469 00:28:06,540 --> 00:28:08,030 Supposing it run off the end of a 470 00:28:08,030 --> 00:28:10,060 conditional, it's pretty arbitrary. 471 00:28:10,060 --> 00:28:13,650 It's up to me as programmer to choose what I want to happen. 472 00:28:13,650 --> 00:28:15,940 It's convenient for me, right now, to write down that this 473 00:28:15,940 --> 00:28:20,100 has a value which is the empty list, doesn't matter. 474 00:28:20,100 --> 00:28:21,530 For error checking, some people might 475 00:28:21,530 --> 00:28:23,110 prefer something else. 476 00:28:23,110 --> 00:28:25,570 But the interesting things are the following ones. 477 00:28:25,570 --> 00:28:27,450 If I've got an else clause-- 478 00:28:31,420 --> 00:28:34,120 You see, if I have a list of clauses, then each clause is a 479 00:28:34,120 --> 00:28:37,480 list. And so the predicate part is 480 00:28:37,480 --> 00:28:40,265 the CAAR of the clauses. 481 00:28:43,560 --> 00:28:48,070 It's the CAR, which is the first part of the first clause 482 00:28:48,070 --> 00:28:51,090 in the list of clauses. 483 00:28:51,090 --> 00:28:55,900 If it's an else, then it means I want my result of the 484 00:28:55,900 --> 00:28:58,400 conditional to be the result of evaluating the matching 485 00:28:58,400 --> 00:28:59,800 expression. 486 00:28:59,800 --> 00:29:10,610 So I eval the CADR. So this is the first clause, the second 487 00:29:10,610 --> 00:29:12,830 element of it, CADAR-- 488 00:29:12,830 --> 00:29:16,360 CADAR of a CAR-- 489 00:29:16,360 --> 00:29:22,195 of the clauses, with respect to the environment. 490 00:29:26,620 --> 00:29:29,630 Now the next possibility is more interesting. 491 00:29:29,630 --> 00:29:34,860 If it's false, if the first predicate in the predicate 492 00:29:34,860 --> 00:29:38,840 list is not an else, and it's not false, if it's not the 493 00:29:38,840 --> 00:29:42,050 word else, and if it's not a false thing-- 494 00:29:42,050 --> 00:29:44,360 Let's write down what it is if it's a false thing. 495 00:29:44,360 --> 00:29:49,590 If the result of evaluating the first 496 00:29:49,590 --> 00:29:52,900 predicate, the clauses-- 497 00:29:55,490 --> 00:30:01,630 respect the environment, if that evaluation yields false, 498 00:30:01,630 --> 00:30:04,180 then it means, I want to look at the next clause. 499 00:30:04,180 --> 00:30:05,990 So I want to discard the first one. 500 00:30:05,990 --> 00:30:15,450 So we just go around loop, evcond, the CDR of the clauses 501 00:30:15,450 --> 00:30:16,700 relative to that environment. 502 00:30:21,240 --> 00:30:27,740 And otherwise, I had a true clause, in which case, what I 503 00:30:27,740 --> 00:30:40,710 want is to evaluate the CADAR of the clauses relative to 504 00:30:40,710 --> 00:30:41,960 that environment. 505 00:30:48,200 --> 00:30:51,210 Boy, it's almost done. 506 00:30:51,210 --> 00:30:53,730 It's quite close to done. 507 00:30:53,730 --> 00:30:56,210 I think we're going to finish this part off. 508 00:30:56,210 --> 00:30:59,530 So just buzzing through this evaluator, but so far you're 509 00:30:59,530 --> 00:31:01,220 seeing almost everything. 510 00:31:01,220 --> 00:31:04,040 Let's look at the next transparency here. 511 00:31:08,980 --> 00:31:11,980 Here is bind. 512 00:31:11,980 --> 00:31:15,460 Bind is for making more table. 513 00:31:15,460 --> 00:31:19,260 And what we are going to do here is make a-- 514 00:31:19,260 --> 00:31:22,800 we're going to make a no-frame for an environment structure. 515 00:31:22,800 --> 00:31:26,230 The environment structure is going to be represented as a 516 00:31:26,230 --> 00:31:28,080 list of frames. 517 00:31:28,080 --> 00:31:30,520 So given an existing environment structure, I'm 518 00:31:30,520 --> 00:31:32,500 going to make a new environment structure by 519 00:31:32,500 --> 00:31:35,270 consing a new frame onto the existing environment 520 00:31:35,270 --> 00:31:38,700 structure, where the new frame consists of the result of 521 00:31:38,700 --> 00:31:41,940 pairing up the variables, which are the bound variables 522 00:31:41,940 --> 00:31:45,610 of the procedure I'm applying, to the values which are the 523 00:31:45,610 --> 00:31:49,690 arguments that were passed that procedure. 524 00:31:49,690 --> 00:31:53,260 This is just making a list, adding a new element to our 525 00:31:53,260 --> 00:31:56,070 list of frames, which is an environment structure, to make 526 00:31:56,070 --> 00:31:58,391 a new environment. 527 00:31:58,391 --> 00:32:01,540 Where pair-up is very simple. 528 00:32:01,540 --> 00:32:04,610 Pair-up is nothing more than if I have a list of variables 529 00:32:04,610 --> 00:32:07,830 and a list of values, well, if I run out of variables and if 530 00:32:07,830 --> 00:32:09,720 I run out of values, everything's OK. 531 00:32:09,720 --> 00:32:12,990 Otherwise, I've given too many arguments. 532 00:32:12,990 --> 00:32:15,390 If I've not run out of variables, but I've run out of 533 00:32:15,390 --> 00:32:18,560 values, that I have too few arguments. 534 00:32:18,560 --> 00:32:20,695 And in the general case, where I don't have any errors, and 535 00:32:20,695 --> 00:32:26,860 I'm not done, then I really am just adding a new pair of the 536 00:32:26,860 --> 00:32:32,810 first variable with the first argument, the first value, 537 00:32:32,810 --> 00:32:37,780 onto a list resulting from pairing-up the rest of the 538 00:32:37,780 --> 00:32:42,950 variables with the rest of the values. 539 00:32:42,950 --> 00:32:46,620 Lookup is of course equally simple. 540 00:32:46,620 --> 00:32:50,230 If I have to look up a symbol in an environment, well, if 541 00:32:50,230 --> 00:32:54,650 the environment is empty, then I've got an unbound variable. 542 00:32:54,650 --> 00:32:59,770 Otherwise, what I'm going to do is use a special pair list 543 00:32:59,770 --> 00:33:02,540 lookup procedure, which we'll have very shortly, of the 544 00:33:02,540 --> 00:33:05,930 symbol in the first frame of the environment. 545 00:33:05,930 --> 00:33:07,670 Since I know the environment is not empty, it must have a 546 00:33:07,670 --> 00:33:09,200 first frame. 547 00:33:09,200 --> 00:33:11,140 So I lookup the symbol in the first frame. 548 00:33:11,140 --> 00:33:15,150 That becomes the value cell here. 549 00:33:15,150 --> 00:33:19,860 And then, if the value cell is empty, if there is no such 550 00:33:19,860 --> 00:33:22,150 value cell, then I have to continue and look at the rest 551 00:33:22,150 --> 00:33:23,720 of the frames. 552 00:33:23,720 --> 00:33:25,990 It means there was nothing found there. 553 00:33:25,990 --> 00:33:29,740 So that's a property of ASSQ is it returns emptiness if it 554 00:33:29,740 --> 00:33:32,010 doesn't find something. 555 00:33:32,010 --> 00:33:35,175 but if it did find something, then I'm going to use the CDR 556 00:33:35,175 --> 00:33:38,080 of the value cell here, which is the thing that was the pair 557 00:33:38,080 --> 00:33:41,050 consisting of the variable and the value. 558 00:33:41,050 --> 00:33:45,000 So the CDR of it is the value part. 559 00:33:45,000 --> 00:33:47,970 Finally, ASSQ is something you've probably seen already. 560 00:33:47,970 --> 00:33:52,400 ASSQ takes a symbol and a list of pairs, and if the list is 561 00:33:52,400 --> 00:33:53,760 empty, it's empty. 562 00:33:53,760 --> 00:33:57,850 If the symbol is the first thing in the list-- 563 00:33:57,850 --> 00:33:59,820 That's an error. 564 00:33:59,820 --> 00:34:04,160 That should be CAAR, C-A-A-R. Everybody note that. 565 00:34:07,730 --> 00:34:08,980 Right there, OK? 566 00:34:13,121 --> 00:34:17,150 And in any case, if the symbol is the CAAR of the A list, 567 00:34:17,150 --> 00:34:22,340 then I want the first, the first pair, in the A list. So, 568 00:34:22,340 --> 00:34:26,300 in other words, if this is the key matching the right entry, 569 00:34:26,300 --> 00:34:30,429 otherwise, I want to look up that symbol in the rest. Sorry 570 00:34:30,429 --> 00:34:35,190 for producing a bug, bugs appear. 571 00:34:35,190 --> 00:34:38,389 Well, in any case, you're pretty much seeing 572 00:34:38,389 --> 00:34:39,639 the whole thing now. 573 00:34:41,880 --> 00:34:45,150 It's a very beautiful thing, even though it's written in an 574 00:34:45,150 --> 00:34:49,600 ugly style, being the kernel of every language. 575 00:34:49,600 --> 00:34:50,210 I suggest that we just-- 576 00:34:50,210 --> 00:34:51,460 let's look at it for a while. 577 00:34:56,749 --> 00:35:49,750 [MUSIC PLAYING] 578 00:35:49,750 --> 00:35:51,000 Are there any questions? 579 00:36:01,180 --> 00:36:04,044 Alright, I suppose it's time to take a small break then. 580 00:36:04,044 --> 00:36:56,780 [MUSIC PLAYING] 581 00:36:56,780 --> 00:36:59,390 OK, now we're just going to do a little bit of practice 582 00:36:59,390 --> 00:37:03,470 understanding what it is we've just shown you. 583 00:37:03,470 --> 00:37:05,700 What we're going to do is go through, in detail, an 584 00:37:05,700 --> 00:37:09,720 evaluation by informally substituting through the 585 00:37:09,720 --> 00:37:11,500 interpreter. 586 00:37:11,500 --> 00:37:14,160 And since we have no assignments or definitions in 587 00:37:14,160 --> 00:37:18,470 this interpreter, we have no possible side effects, and so 588 00:37:18,470 --> 00:37:23,200 the we can do substitution with impunity and not worry 589 00:37:23,200 --> 00:37:25,330 about results. 590 00:37:25,330 --> 00:37:28,800 So the particular problem I'd like to look at is it an 591 00:37:28,800 --> 00:37:30,690 interesting one. 592 00:37:30,690 --> 00:37:41,910 It's the evaluation of quote, open, open, open, lambda of x, 593 00:37:41,910 --> 00:37:55,100 lambda of y plus x y, lambda, lambda, applied to three, 594 00:37:55,100 --> 00:37:58,640 applied to four, in some global environment 595 00:37:58,640 --> 00:37:59,890 which I'll call e0. 596 00:38:04,930 --> 00:38:07,900 So what we have here is a procedure of one argument x, 597 00:38:07,900 --> 00:38:10,980 which produces as its value a procedure of one argument y, 598 00:38:10,980 --> 00:38:14,300 which adds x to y. 599 00:38:14,300 --> 00:38:17,960 We are applying the procedure of one argument x to three. 600 00:38:17,960 --> 00:38:21,400 So x should become three. 601 00:38:21,400 --> 00:38:23,590 And the result of that should be procedure of one argument 602 00:38:23,590 --> 00:38:26,167 y, which will then apply to 4. 603 00:38:28,910 --> 00:38:31,480 And there is a very simple case, they will 604 00:38:31,480 --> 00:38:34,790 then add those results. 605 00:38:34,790 --> 00:38:36,860 And now in order to do that, I want to make a very simple 606 00:38:36,860 --> 00:38:37,660 environment model. 607 00:38:37,660 --> 00:38:41,200 And at this point, you should already have in your mind the 608 00:38:41,200 --> 00:38:44,460 environments that this produces. 609 00:38:44,460 --> 00:38:48,810 But we're going to start out with a global environment, 610 00:38:48,810 --> 00:38:56,740 which I'll call e0, which is that. 611 00:38:56,740 --> 00:39:00,550 And it's going to have in it things, definitions for plus, 612 00:39:00,550 --> 00:39:07,390 and times, and-- 613 00:39:07,390 --> 00:39:08,560 using Greek letters, isn't that 614 00:39:08,560 --> 00:39:11,290 interesting, for the objects-- 615 00:39:11,290 --> 00:39:27,330 and minus, and quotient, and CAR, and CDR, and CONS, and 616 00:39:27,330 --> 00:39:30,480 EQ, and everything else you might imagine in a global 617 00:39:30,480 --> 00:39:31,270 environment. 618 00:39:31,270 --> 00:39:34,590 It's got something there for each of those things, 619 00:39:34,590 --> 00:39:39,220 something the machine is born with, that's e0. 620 00:39:39,220 --> 00:39:42,940 Now what does it mean to do this evaluation? 621 00:39:42,940 --> 00:39:46,120 Well, we go through the set of special forms. First of all, 622 00:39:46,120 --> 00:39:48,670 this is not a number. 623 00:39:48,670 --> 00:39:50,380 This is not a symbol. 624 00:39:53,210 --> 00:39:56,520 Gee, it's not a quoted expression. 625 00:39:56,520 --> 00:40:00,080 This is a quoted expression, but that's not what I 626 00:40:00,080 --> 00:40:00,600 interested in. 627 00:40:00,600 --> 00:40:02,700 The question is, whether or not the thing which is quoted 628 00:40:02,700 --> 00:40:05,890 is quoted expression? 629 00:40:05,890 --> 00:40:07,960 I'm evaluating an expression. 630 00:40:07,960 --> 00:40:11,410 This just says it's this particular expression. 631 00:40:11,410 --> 00:40:12,660 This is not a quoted expression. 632 00:40:15,230 --> 00:40:19,120 It's not a thing that begins with lambda. 633 00:40:19,120 --> 00:40:22,030 It's not a thing that begins with COND. 634 00:40:22,030 --> 00:40:24,630 Therefore, it's an application of its 635 00:40:24,630 --> 00:40:26,310 of an operated operands. 636 00:40:26,310 --> 00:40:28,570 It's a combination. 637 00:40:28,570 --> 00:40:35,230 The combination thus has this as the operator and this is 638 00:40:35,230 --> 00:40:36,480 the operands. 639 00:40:40,130 --> 00:40:43,540 Well, that means that what I'm going to do is transform this 640 00:40:43,540 --> 00:40:54,010 into apply of eval, of quote, open, open lambda of 641 00:40:54,010 --> 00:40:58,180 x, lambda of y-- 642 00:40:58,180 --> 00:40:59,980 I'm evaluating the operator-- 643 00:40:59,980 --> 00:41:13,610 plus x y, in the environment, also e0, with the operands 644 00:41:13,610 --> 00:41:16,330 that I'm going to apply this to, the arguments being the 645 00:41:16,330 --> 00:41:24,450 result of EVLIST, the list containing four, fin e0. 646 00:41:29,010 --> 00:41:33,010 I'm using this funny notation here for e0 because this 647 00:41:33,010 --> 00:41:36,840 should be that environment. 648 00:41:36,840 --> 00:41:38,640 I haven't a name for it, because I have no environment 649 00:41:38,640 --> 00:41:39,890 to name it in. 650 00:41:41,960 --> 00:41:44,630 So this is just a representation of what would 651 00:41:44,630 --> 00:41:47,730 be a quoted expression, if you will. 652 00:41:47,730 --> 00:41:53,040 The data structure, which is the environment, goes there. 653 00:41:53,040 --> 00:41:55,850 Well, that's what we're seeing here. 654 00:41:55,850 --> 00:41:57,370 Well in order to do this, I have to do this, and 655 00:41:57,370 --> 00:41:59,610 I have to do that. 656 00:41:59,610 --> 00:42:03,770 Well this one's easy, so why don't we do that one first. 657 00:42:03,770 --> 00:42:07,780 This turns into apply of eval-- just 658 00:42:07,780 --> 00:42:09,520 copying something now. 659 00:42:09,520 --> 00:42:11,000 Most of the substitution rule is copying. 660 00:42:18,530 --> 00:42:22,100 So I'm going to not say the words when I copy, because 661 00:42:22,100 --> 00:42:23,350 it's faster. 662 00:42:26,100 --> 00:42:34,130 And then the EVLIST is going to turn into a cons, of eval, 663 00:42:34,130 --> 00:42:36,160 of four, in e0-- 664 00:42:38,780 --> 00:42:42,260 because it was not an empty list-- 665 00:42:42,260 --> 00:42:48,910 onto the result of EVLISTing, on the empty list, in e0. 666 00:42:52,580 --> 00:42:54,550 And I'm going to start leaving out steps soon, because it's 667 00:42:54,550 --> 00:42:55,800 going to get boring. 668 00:42:59,870 --> 00:43:05,025 But this is basically the same thing as apply, of eval-- 669 00:43:07,640 --> 00:43:10,230 I'm going to keep doing this-- 670 00:43:10,230 --> 00:43:20,240 the lambda of x, the lambda of y, plus xy, 3, close, e0. 671 00:43:20,240 --> 00:43:21,490 I'm a pretty good machine. 672 00:43:24,690 --> 00:43:27,410 Well, eval of four, that's meets the 673 00:43:27,410 --> 00:43:28,790 question, is it a number. 674 00:43:28,790 --> 00:43:35,280 So that's cons, cons of 4. 675 00:43:35,280 --> 00:43:37,110 And EVLIST of the empty list is the empty 676 00:43:37,110 --> 00:43:39,240 list, so that's this. 677 00:43:43,270 --> 00:43:46,170 And that's very simple to understand, because that means 678 00:43:46,170 --> 00:43:48,710 the list containing four itself. 679 00:43:48,710 --> 00:43:56,340 So this is nothing more than apply of eval, quote, open, 680 00:43:56,340 --> 00:44:06,590 open, lambda of x, lambda of y, plus x y, three applied to, 681 00:44:06,590 --> 00:44:11,678 e0, applied to the list four-- 682 00:44:11,678 --> 00:44:13,940 bang. 683 00:44:13,940 --> 00:44:15,190 So that's that step. 684 00:44:18,100 --> 00:44:20,360 Now let's look at the next, more interesting thing. 685 00:44:20,360 --> 00:44:23,070 What do I do to evaluate that? 686 00:44:23,070 --> 00:44:27,780 Evaluating this means I have to evaluate-- 687 00:44:27,780 --> 00:44:29,460 Well, it's not. 688 00:44:29,460 --> 00:44:31,680 It's nothing but an application. 689 00:44:31,680 --> 00:44:33,570 It's not one of the special things. 690 00:44:33,570 --> 00:44:37,660 If the application of this operator, which we see here-- 691 00:44:37,660 --> 00:44:40,270 here's the operator-- 692 00:44:40,270 --> 00:44:46,570 applied to this operands, that combination. 693 00:44:46,570 --> 00:44:51,390 But we know how to do that, because that's the last case 694 00:44:51,390 --> 00:44:52,370 of the conditional. 695 00:44:52,370 --> 00:44:56,480 So substituting in for this evaluation, it's apply of eval 696 00:44:56,480 --> 00:45:01,160 of the operator in the EVLIST of the operands. 697 00:45:01,160 --> 00:45:12,100 Well, it's apply, of apply, of eval, of quote, open, lambda 698 00:45:12,100 --> 00:45:23,780 of x, lambda of y, plus x y, lambda, lambda, 699 00:45:23,780 --> 00:45:25,350 in environment e0. 700 00:45:30,520 --> 00:45:32,730 I'm going to short circuit the evaluation of the operands , 701 00:45:32,730 --> 00:45:35,230 because they're the same as they were before. 702 00:45:35,230 --> 00:45:38,080 I got a list containing three, apply that, and 703 00:45:38,080 --> 00:45:39,330 apply that to four. 704 00:45:42,780 --> 00:45:44,410 Well let's see. 705 00:45:44,410 --> 00:45:49,450 Eval of a lambda expression produces a procedure object. 706 00:45:52,030 --> 00:46:04,530 So this is apply, of apply, of the procedure object closure, 707 00:46:04,530 --> 00:46:09,420 which contains the body of the procedure, x, which is 708 00:46:09,420 --> 00:46:12,130 lambda-- which binds x [UNINTELLIGIBLE] 709 00:46:12,130 --> 00:46:17,230 the internals of the body, it returns the procedure of one 710 00:46:17,230 --> 00:46:20,630 argument y, which adds x to y. 711 00:46:23,210 --> 00:46:27,930 Environment e0 is now captured in it, because this was 712 00:46:27,930 --> 00:46:30,340 evaluated with respect to e0. 713 00:46:30,340 --> 00:46:33,040 e0 is part now of the closure object. 714 00:46:33,040 --> 00:46:40,050 Apply that to open, three, close, apply, to open, 4, 715 00:46:40,050 --> 00:46:41,300 close, apply. 716 00:46:47,390 --> 00:46:50,220 So going from this step to this step meant that I made up 717 00:46:50,220 --> 00:46:55,060 a procedure object which captured in it e0 as part of 718 00:46:55,060 --> 00:46:57,150 the procedure object. 719 00:46:57,150 --> 00:46:58,620 Now, we're going to pass those to apply. 720 00:46:58,620 --> 00:47:00,480 We have to apply this procedure 721 00:47:00,480 --> 00:47:02,710 to that set of arguments. 722 00:47:02,710 --> 00:47:07,380 Well, but that procedure is not primitive. 723 00:47:07,380 --> 00:47:10,500 It's, in fact, a thing which has got the tag closure, and, 724 00:47:10,500 --> 00:47:13,710 therefore, what we have to do is do a bind. 725 00:47:13,710 --> 00:47:15,830 We have to bind. 726 00:47:15,830 --> 00:47:21,850 A new environment is made at this point, which has as its 727 00:47:21,850 --> 00:47:26,980 parent environment the one over here, e0, that 728 00:47:26,980 --> 00:47:28,230 environment. 729 00:47:30,320 --> 00:47:31,570 And we'll call this one, e1. 730 00:47:34,620 --> 00:47:36,040 Now what's bound in there? 731 00:47:36,040 --> 00:47:38,620 x is bound to three. 732 00:47:38,620 --> 00:47:41,480 So I have x equal three. 733 00:47:41,480 --> 00:47:42,730 That's what's in there. 734 00:47:44,940 --> 00:47:46,240 And we'll call that e1. 735 00:47:46,240 --> 00:47:51,940 So what this transforms into is an eval of the body of 736 00:47:51,940 --> 00:47:56,740 this, which is this, the body of that procedure, in the 737 00:47:56,740 --> 00:48:00,290 environment that you just saw. 738 00:48:00,290 --> 00:48:11,480 So that's an apply, of eval, quote, open, lambda of y, plus 739 00:48:11,480 --> 00:48:12,750 x y-- the body-- 740 00:48:15,270 --> 00:48:16,520 in e1. 741 00:48:20,660 --> 00:48:26,040 And apply the result of that to four, open, close, 4-- 742 00:48:26,040 --> 00:48:28,680 list of arguments. 743 00:48:28,680 --> 00:48:31,600 Well, that's sensible enough because evaluating a lambda, I 744 00:48:31,600 --> 00:48:33,110 know what to do. 745 00:48:33,110 --> 00:48:43,680 That means I apply, the procedure which is closure, 746 00:48:43,680 --> 00:48:52,150 binds one argument y, adds x to y, with e1 captured in it. 747 00:48:55,790 --> 00:48:57,800 And you should really see this. 748 00:48:57,800 --> 00:49:00,140 I somehow manufactured a closure. 749 00:49:00,140 --> 00:49:01,790 I should've put this here. 750 00:49:01,790 --> 00:49:03,040 There was one over here too. 751 00:49:06,230 --> 00:49:08,080 Well, there's one here now. 752 00:49:08,080 --> 00:49:13,710 I've captured e1, and this is the procedure of one argument 753 00:49:13,710 --> 00:49:17,880 y, whatever this is. 754 00:49:17,880 --> 00:49:20,435 That's what that is there, that closure. 755 00:49:23,040 --> 00:49:26,230 I'm going to apply that to four. 756 00:49:30,690 --> 00:49:31,940 Well, that's easy enough. 757 00:49:36,830 --> 00:49:39,720 That means I have to make a new environment by copying 758 00:49:39,720 --> 00:49:45,030 this pointer, which was the pointer of the procedure, 759 00:49:45,030 --> 00:49:49,540 which binds y equal 4 with that environment. 760 00:49:49,540 --> 00:49:52,460 And here's my new environment, which I'll call e2. 761 00:49:55,870 --> 00:49:58,990 And, of course, this application then is evaluate 762 00:49:58,990 --> 00:50:01,910 the body in e2. 763 00:50:01,910 --> 00:50:10,830 So this is eval, the body, which is plus x y, in the 764 00:50:10,830 --> 00:50:13,710 environment e2. 765 00:50:13,710 --> 00:50:22,220 But this is an application, so this is the apply, of eval, 766 00:50:22,220 --> 00:50:37,340 plus in e2, an EVLIST, quote, open, x y, in e2. 767 00:50:44,880 --> 00:50:45,590 Well, but let's see. 768 00:50:45,590 --> 00:50:52,480 That is apply, the object which is a 769 00:50:52,480 --> 00:50:54,190 result of that and plus. 770 00:50:54,190 --> 00:50:57,920 So here we are in e2, plus is not here, it's not here, oh, 771 00:50:57,920 --> 00:51:01,780 yes, but's here as some primitive operator. 772 00:51:01,780 --> 00:51:04,745 So it's the primitive operator for addition. 773 00:51:08,490 --> 00:51:14,370 Apply that to the result of evaluating x and y in e2. 774 00:51:14,370 --> 00:51:18,340 But we can see that x is three and y is four. 775 00:51:18,340 --> 00:51:23,936 So that's a three and four, here. 776 00:51:23,936 --> 00:51:26,280 And that magically produces for me a seven. 777 00:51:30,520 --> 00:51:33,460 I wanted to go through this so you would see, essentially, 778 00:51:33,460 --> 00:51:36,960 one important ingredient, which is what's being passed 779 00:51:36,960 --> 00:51:40,470 around, and who owns what, and what his job is. 780 00:51:40,470 --> 00:51:41,700 So what do we have here? 781 00:51:41,700 --> 00:51:46,520 We have eval, and we have apply, the two main players. 782 00:51:49,370 --> 00:51:52,320 And there is a big loop the goes around like this. 783 00:51:52,320 --> 00:52:00,780 Which is eval produces a procedure and 784 00:52:00,780 --> 00:52:06,270 arguments for apply. 785 00:52:06,270 --> 00:52:09,710 Now some things eval could do by itself. 786 00:52:09,710 --> 00:52:10,860 Those are little self things here. 787 00:52:10,860 --> 00:52:12,700 They're not interesting. 788 00:52:12,700 --> 00:52:16,240 Also eval evaluates all of the arguments, one after another. 789 00:52:16,240 --> 00:52:17,650 That's not very interesting. 790 00:52:17,650 --> 00:52:21,540 Apply can apply some procedures like plus, not very 791 00:52:21,540 --> 00:52:22,300 interesting. 792 00:52:22,300 --> 00:52:25,520 However, if apply can't apply a procedure like plus, it 793 00:52:25,520 --> 00:52:32,880 produces an expression and environment for eval. 794 00:52:35,470 --> 00:52:39,770 The procedural arguments wrap up essentially the state of a 795 00:52:39,770 --> 00:52:43,740 computation and, certainly, the expression of environment. 796 00:52:43,740 --> 00:52:45,600 And so what we're actually going to do next is not the 797 00:52:45,600 --> 00:52:47,570 complete state, because it doesn't say 798 00:52:47,570 --> 00:52:48,820 who wants the answers. 799 00:52:51,280 --> 00:52:53,500 But what we're going to do-- it's always got something like 800 00:52:53,500 --> 00:52:56,580 an expression of environment or procedure and arguments as 801 00:52:56,580 --> 00:52:58,970 the main loop that we're going around. 802 00:52:58,970 --> 00:53:01,500 There are minor little sub loops like eval through 803 00:53:01,500 --> 00:53:11,030 EVLIST, or eval through evcond, or apply through a 804 00:53:11,030 --> 00:53:12,280 primitive apply. 805 00:53:16,140 --> 00:53:18,500 But they're not the essential things. 806 00:53:18,500 --> 00:53:21,860 So that's what I wanted you to see. 807 00:53:21,860 --> 00:53:23,110 Are there any questions? 808 00:53:25,930 --> 00:53:28,690 Yes. 809 00:53:28,690 --> 00:53:32,670 AUDIENCE: I'm trying to understand how x got down to 810 00:53:32,670 --> 00:53:37,070 three instead of four. 811 00:53:37,070 --> 00:53:38,540 At the early part of the-- 812 00:53:38,540 --> 00:53:41,310 PROFESSOR: Here. 813 00:53:41,310 --> 00:53:43,310 You want to know how x got down to three? 814 00:53:43,310 --> 00:53:49,770 AUDIENCE: Because x is the outer procedure, and x and y 815 00:53:49,770 --> 00:53:51,040 are the inner procedure. 816 00:53:51,040 --> 00:53:52,570 PROFESSOR: Fine. 817 00:53:52,570 --> 00:53:55,280 Well, I was very careful and mechanical. 818 00:53:55,280 --> 00:53:57,350 First of all, I should write those procedures again for 819 00:53:57,350 --> 00:54:00,610 you, pretty printed. 820 00:54:00,610 --> 00:54:02,260 First order of business, because you're probably not 821 00:54:02,260 --> 00:54:03,830 reading them well. 822 00:54:03,830 --> 00:54:08,500 So I have here that procedure of-- 823 00:54:08,500 --> 00:54:11,280 was it x over there-- 824 00:54:11,280 --> 00:54:12,690 which is-- 825 00:54:12,690 --> 00:54:20,710 value of that procedure of y, which adds x to y, lambda, 826 00:54:20,710 --> 00:54:25,380 lambda, applied that to three, takes the result of that, and 827 00:54:25,380 --> 00:54:26,140 applied that to four. 828 00:54:26,140 --> 00:54:28,810 Is that not what I wrote? 829 00:54:28,810 --> 00:54:34,170 Now, you should immediately see that here is an 830 00:54:34,170 --> 00:54:35,150 application-- 831 00:54:35,150 --> 00:54:37,400 let me get a white piece of chalk-- 832 00:54:37,400 --> 00:54:40,735 here is an application, a combination. 833 00:54:44,300 --> 00:54:48,270 That combination has this as the operator 834 00:54:48,270 --> 00:54:51,040 and this as the operand. 835 00:54:51,040 --> 00:54:54,900 The three is going in for the x here. 836 00:54:54,900 --> 00:54:58,720 The result of this is a procedure of one argument y, 837 00:54:58,720 --> 00:55:01,530 which gets applied to four. 838 00:55:01,530 --> 00:55:04,190 So you just weren't reading the expression right. 839 00:55:04,190 --> 00:55:11,580 The way you see that over here is that here I have the actual 840 00:55:11,580 --> 00:55:13,340 procedure object, x. 841 00:55:13,340 --> 00:55:18,980 It's getting applied to three, the list containing three. 842 00:55:18,980 --> 00:55:20,350 What I'm left over with is something which 843 00:55:20,350 --> 00:55:24,080 gets applied to four. 844 00:55:24,080 --> 00:55:25,330 Are there any other questions? 845 00:55:28,600 --> 00:55:30,900 Time for our next small break then. 846 00:55:30,900 --> 00:55:33,735 Thank you. 847 00:55:33,735 --> 00:56:08,410 [MUSIC PLAYING] 848 00:56:08,410 --> 00:56:14,730 Let's see, at this point, you should be getting the feeling, 849 00:56:14,730 --> 00:56:16,630 what's this nonsense this Sussman 850 00:56:16,630 --> 00:56:17,960 character is feeding me? 851 00:56:20,740 --> 00:56:24,800 There's an awful lot of strange nonsense here. 852 00:56:24,800 --> 00:56:28,300 After all, he purported to explain to me Lisp, and he 853 00:56:28,300 --> 00:56:30,892 wrote me a Lisp program on the blackboard. 854 00:56:30,892 --> 00:56:33,560 The Lisp program was intended to be interpreted for Lisp, 855 00:56:33,560 --> 00:56:35,280 but you need a Lisp interpreter in order to 856 00:56:35,280 --> 00:56:38,370 understand that program. 857 00:56:38,370 --> 00:56:41,160 How could that program have told me anything there is to 858 00:56:41,160 --> 00:56:44,150 be known about Lisp? 859 00:56:44,150 --> 00:56:45,795 How is that not completely vacuous? 860 00:56:48,490 --> 00:56:50,990 It's a very strange thing. 861 00:56:50,990 --> 00:56:52,430 Does it tell me anything at all? 862 00:56:56,070 --> 00:56:59,230 Well, you see, the whole thing is sort of like these Escher's 863 00:56:59,230 --> 00:57:03,105 hands that we see on this slide. 864 00:57:06,180 --> 00:57:11,750 Yes, eval and apply each sort of draw each other and 865 00:57:11,750 --> 00:57:15,690 construct the real thing, which can sit 866 00:57:15,690 --> 00:57:17,110 out and draw itself. 867 00:57:17,110 --> 00:57:19,300 Escher was a very brilliant man, he just didn't know the 868 00:57:19,300 --> 00:57:20,550 names of these spirits. 869 00:57:23,910 --> 00:57:27,700 Well, I'm going to do now, is I'm going to try to convince 870 00:57:27,700 --> 00:57:33,060 you that both this mean something, and, as a aside, 871 00:57:33,060 --> 00:57:36,090 I'm going to show you why you don't need definitions. 872 00:57:36,090 --> 00:57:38,760 Just turns out that that sort of falls out, why definitions 873 00:57:38,760 --> 00:57:42,990 are not essential in a mathematical sense for doing 874 00:57:42,990 --> 00:57:44,890 all the things we need to do for computing. 875 00:57:49,070 --> 00:57:50,690 Well, let's see here. 876 00:57:50,690 --> 00:57:54,870 Consider the following small program, what does it mean? 877 00:57:54,870 --> 00:57:57,035 This is a program for computing exponentials. 878 00:58:07,270 --> 00:58:13,350 The exponential of x to the nth power is if-- 879 00:58:16,910 --> 00:58:22,070 and is zero, then the result is one. 880 00:58:22,070 --> 00:58:29,520 Otherwise, I want the product of x and the result of 881 00:58:29,520 --> 00:58:33,930 exponentiating x to the n minus one power. 882 00:58:42,858 --> 00:58:46,630 I think I got it right. 883 00:58:46,630 --> 00:58:49,470 Now this is a recursive definition. 884 00:58:49,470 --> 00:58:53,930 It's a definition of the exponentiation procedure in 885 00:58:53,930 --> 00:58:56,410 terms of itself. 886 00:58:56,410 --> 00:59:00,710 And, as it has been mentioned before, your high school 887 00:59:00,710 --> 00:59:03,010 geometry teacher probably gave you a hard time 888 00:59:03,010 --> 00:59:05,650 about things like that. 889 00:59:05,650 --> 00:59:07,910 Was that justified? 890 00:59:07,910 --> 00:59:13,430 Why does this self referential definition make any sense? 891 00:59:13,430 --> 00:59:15,060 Well, first of all, I'm going to convince you that your high 892 00:59:15,060 --> 00:59:17,600 school geometry teacher was I telling you nonsense. 893 00:59:20,370 --> 00:59:24,490 Consider the following set of definitions here. 894 00:59:24,490 --> 00:59:33,070 x plus y equals three, and x minus y equal one. 895 00:59:33,070 --> 00:59:36,170 Well, gee, this tells you x in terms of y, and this one tells 896 00:59:36,170 --> 00:59:37,490 you y in terms of x, presumably. 897 00:59:40,150 --> 00:59:42,950 And yet this happens to have a unique solution in x and y. 898 00:59:55,910 --> 01:00:06,600 However, I could also write two x plus two y is six. 899 01:00:06,600 --> 01:00:09,610 These two equations have an infinite number solutions. 900 01:00:15,730 --> 01:00:21,520 And I could write you, for example, x minus y equal 2, 901 01:00:21,520 --> 01:00:24,070 and these two equations have no solutions. 902 01:00:29,820 --> 01:00:32,350 Well, I have here three sets of simultaneous linear 903 01:00:32,350 --> 01:00:39,510 equations, this set, this set, and this set. 904 01:00:39,510 --> 01:00:42,900 But they have different numbers of solutions. 905 01:00:42,900 --> 01:00:45,760 The number of solutions is not in the form of the equations. 906 01:00:45,760 --> 01:00:48,350 They all three sets have the same form. 907 01:00:48,350 --> 01:00:50,205 The number of solutions is in the content. 908 01:00:53,000 --> 01:00:55,510 I can't tell by looking at the form of a definition whether 909 01:00:55,510 --> 01:00:59,660 it makes sense, only by its detailed content. 910 01:00:59,660 --> 01:01:02,170 What are the coefficients, for example, in the 911 01:01:02,170 --> 01:01:05,100 case of linear equations? 912 01:01:05,100 --> 01:01:07,440 So I shouldn't expect to be able to tell looking at 913 01:01:07,440 --> 01:01:11,500 something like this, from some simple things like, oh yes, 914 01:01:11,500 --> 01:01:16,030 EXPT is the solution of this recursion equation. 915 01:01:16,030 --> 01:01:22,110 Expt is the procedure which if substituted in here, 916 01:01:22,110 --> 01:01:26,040 gives me EXPT back. 917 01:01:26,040 --> 01:01:30,750 I can't tell, looking at this form, whether or not there's a 918 01:01:30,750 --> 01:01:33,970 single, unique solution for EXPT, an infinite number of 919 01:01:33,970 --> 01:01:37,200 solutions, or no solutions. 920 01:01:37,200 --> 01:01:38,930 It's got to be how it counts and things 921 01:01:38,930 --> 01:01:40,490 like that, the details. 922 01:01:40,490 --> 01:01:42,900 And it's harder in programming than linear algebra. 923 01:01:42,900 --> 01:01:45,210 There aren't too many theorems about it in programming. 924 01:01:48,450 --> 01:01:50,990 Well, I want to rewrite these equations a little 925 01:01:50,990 --> 01:01:53,970 bit, these over here. 926 01:01:53,970 --> 01:01:55,560 Because what we're investigating is 927 01:01:55,560 --> 01:01:56,770 equations like this. 928 01:01:56,770 --> 01:01:58,820 But I want to play a little with equations like this that 929 01:01:58,820 --> 01:02:02,050 we understand, just so we get some insight into 930 01:02:02,050 --> 01:02:04,730 this kind of question. 931 01:02:04,730 --> 01:02:07,870 We could rewrite our equations here, say these two, the ones 932 01:02:07,870 --> 01:02:17,070 that are interesting, as x equals three minus y, and y 933 01:02:17,070 --> 01:02:19,380 equals x minus one. 934 01:02:22,010 --> 01:02:24,050 What do we call this transformation? 935 01:02:24,050 --> 01:02:26,095 This is a linear transformation, t. 936 01:02:29,430 --> 01:02:35,390 Then what we're getting here is an equation x y 937 01:02:35,390 --> 01:02:37,370 equals t of x y. 938 01:02:42,990 --> 01:02:44,560 What am I looking for? 939 01:02:44,560 --> 01:02:47,040 I'm looking for a fixed point of t. 940 01:02:47,040 --> 01:02:59,350 The solution is a fixed point of t. 941 01:03:01,910 --> 01:03:04,830 So the methods we should have for looking for solutions to 942 01:03:04,830 --> 01:03:09,230 equations, if I can do it by fixed points, might be 943 01:03:09,230 --> 01:03:10,880 applicable. 944 01:03:10,880 --> 01:03:13,710 If I have a means of finding a solution to an equations by 945 01:03:13,710 --> 01:03:15,690 fixed points-- 946 01:03:15,690 --> 01:03:18,620 just, might not work-- 947 01:03:18,620 --> 01:03:21,160 but it might be applicable to investigating solutions of 948 01:03:21,160 --> 01:03:22,410 equations like this. 949 01:03:27,240 --> 01:03:30,260 But what I want you to feel is that this is an equation. 950 01:03:30,260 --> 01:03:32,930 It's an expression with several instances of various 951 01:03:32,930 --> 01:03:39,020 names which puts a constraint on the name, saying what that 952 01:03:39,020 --> 01:03:42,770 name could have as its value, rather than some sort of 953 01:03:42,770 --> 01:03:45,010 mechanical process of substitution right now. 954 01:03:47,740 --> 01:03:51,220 This is an equation which I'm going to try to solve. 955 01:03:51,220 --> 01:03:53,960 Well, let's play around and solve it. 956 01:03:53,960 --> 01:03:57,800 First of all, I want to write down the function which 957 01:03:57,800 --> 01:04:00,320 corresponds to t. 958 01:04:00,320 --> 01:04:02,670 First I want to write down the function which corresponds to 959 01:04:02,670 --> 01:04:06,960 t whose fixed point is the answer to this question. 960 01:04:11,950 --> 01:04:14,240 Well, let's consider the following procedure f. 961 01:04:16,870 --> 01:04:19,340 I claim it computes that function. 962 01:04:19,340 --> 01:04:26,860 f is that procedure of one argument g, which is that 963 01:04:26,860 --> 01:04:33,430 procedure of two arguments x and n. 964 01:04:33,430 --> 01:04:42,410 Which have the property that if n is zero, then the result 965 01:04:42,410 --> 01:04:56,050 is one, otherwise, the result is the product of x and g, 966 01:04:56,050 --> 01:05:00,690 applied to x, and minus n1. 967 01:05:03,370 --> 01:05:07,900 g, times, else, COND, lambda, lambda-- 968 01:05:11,900 --> 01:05:17,230 Here f is a procedure, which if I had a solution to that 969 01:05:17,230 --> 01:05:23,640 equation, if I had a good exponentiation procedure, and 970 01:05:23,640 --> 01:05:29,500 I applied f to that procedure, then the result would be a 971 01:05:29,500 --> 01:05:30,930 good exponentiation procedure. 972 01:05:37,460 --> 01:05:39,420 Because, what does it do? 973 01:05:39,420 --> 01:05:44,200 Well, all it is is exposing g were a good exponentiation 974 01:05:44,200 --> 01:05:48,010 procedure, well then this would produce, as its value, a 975 01:05:48,010 --> 01:05:51,650 procedure to arguments x and n, such that if n were 0, the 976 01:05:51,650 --> 01:05:53,360 result would be one, which is certainly true of 977 01:05:53,360 --> 01:05:54,670 exponentiation. 978 01:05:54,670 --> 01:05:57,730 Otherwise, it will be the result of multiplying x by the 979 01:05:57,730 --> 01:06:01,750 exponentiation procedure given to me with x and n minus one 980 01:06:01,750 --> 01:06:03,470 as arguments. 981 01:06:03,470 --> 01:06:05,680 So if this computed the correct exponentiation for n 982 01:06:05,680 --> 01:06:10,500 minus one, then this would be the correct exponentiation for 983 01:06:10,500 --> 01:06:13,370 exponent n, so this would have been the right 984 01:06:13,370 --> 01:06:14,620 exponentiation procedure. 985 01:06:17,500 --> 01:06:26,560 So what I really want to say here is E-X-P-T is a fixed 986 01:06:26,560 --> 01:06:32,320 point of f. 987 01:06:37,550 --> 01:06:40,060 Now our problem is there might be more than one fixed point. 988 01:06:40,060 --> 01:06:43,270 There might be no fixed points. 989 01:06:43,270 --> 01:06:44,810 I have to go hunting for the fixed points. 990 01:06:48,290 --> 01:06:49,540 Got to solve this equation. 991 01:06:52,160 --> 01:06:55,580 Well there are various ways to hunt for fixed points. 992 01:06:55,580 --> 01:06:58,080 Of course, the one we played with at the beginning of this 993 01:06:58,080 --> 01:07:00,815 term worked for cosine. 994 01:07:06,080 --> 01:07:09,235 Go into radians mode on your calculator and push cosine, 995 01:07:09,235 --> 01:07:12,990 and just keep doing it, and you get to some number which 996 01:07:12,990 --> 01:07:16,090 is about 0.73 or 0.74. 997 01:07:16,090 --> 01:07:17,340 I can't remember which. 998 01:07:22,900 --> 01:07:27,170 By iterating a function, whose fixed point I'm searching for, 999 01:07:27,170 --> 01:07:32,090 it is sometimes the case that that function will converge in 1000 01:07:32,090 --> 01:07:33,770 producing the fixed point. 1001 01:07:33,770 --> 01:07:39,910 I think we luck out in this case, so let's look for it. 1002 01:07:39,910 --> 01:07:48,030 Let's look at this slide. 1003 01:07:48,030 --> 01:07:51,390 Consider the following sequence of procedures. 1004 01:07:56,400 --> 01:08:02,940 e0 over here is the procedure which does nothing at all. 1005 01:08:02,940 --> 01:08:05,390 It's the procedure which produces an error for any 1006 01:08:05,390 --> 01:08:07,780 arguments you give it. 1007 01:08:07,780 --> 01:08:09,030 It's basically useless. 1008 01:08:14,480 --> 01:08:20,080 Well, however, I can make an approximation. 1009 01:08:20,080 --> 01:08:22,930 Let's consider it the worst possible approximation to 1010 01:08:22,930 --> 01:08:26,990 exponentiation, because it does nothing. 1011 01:08:26,990 --> 01:08:34,170 Well, supposing I substituted e0 for g by calling f, as you 1012 01:08:34,170 --> 01:08:37,380 see over here on e0. 1013 01:08:37,380 --> 01:08:40,729 So you see over here, have e0 there. 1014 01:08:40,729 --> 01:08:43,859 Then gee, what's e1? 1015 01:08:43,859 --> 01:08:47,189 e1 is a procedure which exponentiate things to the 0th 1016 01:08:47,189 --> 01:08:49,325 power, with no trouble. 1017 01:08:49,325 --> 01:08:52,420 It gets the right answer, anything to the zero is one, 1018 01:08:52,420 --> 01:08:54,250 and it makes an error on anything else. 1019 01:08:57,390 --> 01:09:06,040 Well, now what if I take e1 and I substitute if for g by 1020 01:09:06,040 --> 01:09:07,310 calling f on e1? 1021 01:09:10,500 --> 01:09:15,670 Oh gosh, I have here a procedure of two arguments. 1022 01:09:15,670 --> 01:09:18,250 Now remember e1 was appropriate for taking 1023 01:09:18,250 --> 01:09:24,200 exponentiations of 0, for raising to the 0 exponent. 1024 01:09:24,200 --> 01:09:27,910 So here, is n is 0, the result is one, so this guy is good 1025 01:09:27,910 --> 01:09:29,520 for that too. 1026 01:09:29,520 --> 01:09:32,479 However, I can use something for raising to the 0th power 1027 01:09:32,479 --> 01:09:35,979 to multiply it by x to raise something to the first power. 1028 01:09:35,979 --> 01:09:39,670 So e2 is good for both power 0 and one. 1029 01:09:43,800 --> 01:09:47,899 And e3 is constructed from e2 in the same way. 1030 01:09:47,899 --> 01:09:52,240 And e3, of course, by the same argument is good for powers 0, 1031 01:09:52,240 --> 01:09:55,120 one, and two. 1032 01:09:55,120 --> 01:10:00,140 And so I will assert for you, without proof, because the 1033 01:10:00,140 --> 01:10:02,520 proof is horribly difficult. 1034 01:10:02,520 --> 01:10:04,050 And that's the sort of thing that people called 1035 01:10:04,050 --> 01:10:07,710 denotational semanticists do. 1036 01:10:07,710 --> 01:10:10,265 This great idea was invented by Scott and Strachey. 1037 01:10:14,240 --> 01:10:17,110 They're very famous mathematician types who 1038 01:10:17,110 --> 01:10:21,030 invented the interpretation for these programs that we 1039 01:10:21,030 --> 01:10:24,240 have that I'm talking to you about right now. 1040 01:10:24,240 --> 01:10:28,950 And they proved, by topology that there is such a fixed 1041 01:10:28,950 --> 01:10:32,220 point in the cases that we want. 1042 01:10:32,220 --> 01:10:41,180 But the assertion is E-X-P-T is limit as n goes 1043 01:10:41,180 --> 01:10:43,680 to infinity of em. 1044 01:10:43,680 --> 01:10:47,900 and And that we've constructed this by the following way. 1045 01:10:50,520 --> 01:10:57,530 --is Well, it's f of, f of, f of, f of, f of-- 1046 01:10:57,530 --> 01:11:01,120 f applied to anything at all. 1047 01:11:01,120 --> 01:11:04,070 It didn't matter what that was, because, in fact, this 1048 01:11:04,070 --> 01:11:05,320 always produces an error. 1049 01:11:07,540 --> 01:11:08,790 Applied to this-- 1050 01:11:12,840 --> 01:11:16,380 That's by infinite nesting of f's. 1051 01:11:16,380 --> 01:11:19,760 So now my problem is to make some infinite things. 1052 01:11:22,590 --> 01:11:24,920 We need some infinite things. 1053 01:11:24,920 --> 01:11:28,980 How am I going to nest up an f an infinite number of times? 1054 01:11:28,980 --> 01:11:32,380 I'd better construct this. 1055 01:11:32,380 --> 01:11:32,930 Well, I don't know. 1056 01:11:32,930 --> 01:11:34,810 How would I make an infinite loop at all? 1057 01:11:34,810 --> 01:11:37,090 Let's take a very simple infinite loop, the simplest 1058 01:11:37,090 --> 01:11:38,340 infinite loop imaginable. 1059 01:11:43,550 --> 01:11:48,070 If I were to take that procedure of one argument x 1060 01:11:48,070 --> 01:11:57,580 which applies x to x and apply that to the procedure of one 1061 01:11:57,580 --> 01:12:05,320 argument x which applies x to x, then this 1062 01:12:05,320 --> 01:12:07,440 is an infinite loop. 1063 01:12:07,440 --> 01:12:09,980 The reason why this is an infinite loop is as follows. 1064 01:12:09,980 --> 01:12:14,390 The way I understand this is I substitute the argument for 1065 01:12:14,390 --> 01:12:18,850 the formal parameter in the body. 1066 01:12:18,850 --> 01:12:22,590 But if I do that, I take for each of these x's, I 1067 01:12:22,590 --> 01:12:25,740 substitute one of these, making a copy of the original 1068 01:12:25,740 --> 01:12:28,410 expression I just started with, the 1069 01:12:28,410 --> 01:12:29,660 simplest infinite loop. 1070 01:12:35,440 --> 01:12:40,750 Now I want to tell you about a particular operator which is 1071 01:12:40,750 --> 01:12:43,090 constructed by a perturbation from this infinite loop. 1072 01:12:47,040 --> 01:12:48,290 I'll call it y. 1073 01:12:52,290 --> 01:12:56,680 This is called Curry's Paradoxical Combinator of y 1074 01:12:56,680 --> 01:13:00,510 after a fellow by the name of Curry, who was a logician of 1075 01:13:00,510 --> 01:13:04,480 the 1930s also. 1076 01:13:04,480 --> 01:13:08,670 And if I have a procedure of one argument f, what's it 1077 01:13:08,670 --> 01:13:09,330 going to have in it? 1078 01:13:09,330 --> 01:13:13,420 It's going to have a kind of infinite loop in it, which is 1079 01:13:13,420 --> 01:13:21,670 that procedure of one argument x which applies f to x of x, 1080 01:13:21,670 --> 01:13:25,820 applied to that procedure of one argument x, which applies 1081 01:13:25,820 --> 01:13:27,899 f to f of x. 1082 01:13:32,300 --> 01:13:34,590 Now what's this do? 1083 01:13:34,590 --> 01:13:42,950 Suppose we apply y to F. Well, that's easy enough. 1084 01:13:42,950 --> 01:13:46,910 That's this capital F over here. 1085 01:13:46,910 --> 01:13:48,670 Well, the easiest thing to say there is, I 1086 01:13:48,670 --> 01:13:49,920 substitute F for here. 1087 01:13:55,320 --> 01:13:58,460 So that's going to give me, basically-- 1088 01:13:58,460 --> 01:14:02,800 because then I'm going to substitute this for x in here. 1089 01:14:08,970 --> 01:14:10,810 Let me actually do it in steps, so you can see it 1090 01:14:10,810 --> 01:14:11,730 completely. 1091 01:14:11,730 --> 01:14:15,020 I'm going to be very careful. 1092 01:14:15,020 --> 01:14:27,510 This is open, open, lambda of x , capital F, x, x, applied 1093 01:14:27,510 --> 01:14:37,910 to itself, F of x of x. 1094 01:14:37,910 --> 01:14:45,600 Substituting this for this in here, this is F applied to-- 1095 01:14:45,600 --> 01:14:47,040 what is it-- 1096 01:14:47,040 --> 01:14:53,850 substituting this in here, open, open, lambda of x, F, of 1097 01:14:53,850 --> 01:15:08,910 x and x, applied to lambda of x, F of x of x, F, lambda, 1098 01:15:08,910 --> 01:15:11,510 pair, F. 1099 01:15:11,510 --> 01:15:13,420 Oh, but what is this? 1100 01:15:13,420 --> 01:15:17,490 This thing over here that I just computed, is 1101 01:15:17,490 --> 01:15:20,030 this thing over here. 1102 01:15:20,030 --> 01:15:23,370 But I just wrapped another F around it. 1103 01:15:23,370 --> 01:15:27,850 So by applying y to F, I make an infinite series of F's. 1104 01:15:27,850 --> 01:15:30,520 If I just let this run forever, I'll just keep making 1105 01:15:30,520 --> 01:15:33,170 more and more F's outside. 1106 01:15:33,170 --> 01:15:35,600 I ran an infinite loop which is useless, but it doesn't 1107 01:15:35,600 --> 01:15:36,855 matter that the inside is useless. 1108 01:15:40,220 --> 01:15:53,900 So y of F is F applied to y of F. So y is a magical thing 1109 01:15:53,900 --> 01:15:58,840 which, when applied to some function, produces the object 1110 01:15:58,840 --> 01:16:03,200 which is the fixed point of that function, if it exists, 1111 01:16:03,200 --> 01:16:04,450 and if this all works. 1112 01:16:07,910 --> 01:16:10,380 Because, indeed, if I take y of F and put it into F, I get 1113 01:16:10,380 --> 01:16:11,630 y of F out. 1114 01:16:16,240 --> 01:16:20,750 Now I want you to think this in terms of the eval-apply 1115 01:16:20,750 --> 01:16:23,860 interpreter for a bit. 1116 01:16:23,860 --> 01:16:28,540 I wrote down a whole bunch of recursion equations out there. 1117 01:16:28,540 --> 01:16:30,210 They're simultaneous in the same way these are 1118 01:16:30,210 --> 01:16:31,470 simultaneous equations. 1119 01:16:31,470 --> 01:16:33,310 Exponentiation was not a simultaneous equation. 1120 01:16:33,310 --> 01:16:38,150 It was only one variable I was looking for a meaning for. 1121 01:16:38,150 --> 01:16:41,210 But what Lisp is is the fixed point of the process which 1122 01:16:41,210 --> 01:16:44,740 says, if I knew what Lisp was and substituted it in for 1123 01:16:44,740 --> 01:16:47,780 eval, and apply, and so on, on the right hand sides of all 1124 01:16:47,780 --> 01:16:51,930 those recursion equations, then if it was a real good 1125 01:16:51,930 --> 01:16:55,340 Lisp, is a real one, then the left hand side 1126 01:16:55,340 --> 01:16:58,220 would also be Lisp. 1127 01:16:58,220 --> 01:16:59,565 So I made sense of that definition. 1128 01:17:02,420 --> 01:17:05,410 Now whether or not there's an answer isn't so obvious. 1129 01:17:05,410 --> 01:17:07,740 I can't attack that. 1130 01:17:07,740 --> 01:17:09,160 Now these arguments that I'm giving you 1131 01:17:09,160 --> 01:17:10,660 now are quite dangerous. 1132 01:17:10,660 --> 01:17:13,570 Let's look over here. 1133 01:17:13,570 --> 01:17:14,610 These are limit arguments. 1134 01:17:14,610 --> 01:17:17,020 We're talking about limits, and it's really calculus, or 1135 01:17:17,020 --> 01:17:21,255 topology, or something like that, a kind of analysis. 1136 01:17:21,255 --> 01:17:23,380 Now here's an argument that you all believe. 1137 01:17:23,380 --> 01:17:27,010 And I want to make sure you realize that I could be 1138 01:17:27,010 --> 01:17:29,660 bullshitting you. 1139 01:17:29,660 --> 01:17:30,910 What is this? 1140 01:17:34,250 --> 01:17:40,300 u is the sum of 1/2, 1/4, and 1/8, and so on, the sum of a 1141 01:17:40,300 --> 01:17:42,820 geometric series. 1142 01:17:42,820 --> 01:17:44,820 And, of course, I could play a game here. 1143 01:17:44,820 --> 01:17:47,570 u minus one is 1/2, plus 1/4, plus 1/8, and so on. 1144 01:17:53,590 --> 01:17:56,190 What I could do here-- 1145 01:17:56,190 --> 01:17:56,680 oops. 1146 01:17:56,680 --> 01:17:58,920 There is a parentheses error here. 1147 01:17:58,920 --> 01:18:02,740 But I can put here two times u minus one is one plus 1/2, 1148 01:18:02,740 --> 01:18:03,990 plus 1/4, plus 1/8. 1149 01:18:07,570 --> 01:18:08,820 Can I fix that? 1150 01:18:14,010 --> 01:18:16,125 Yes, well. 1151 01:18:19,520 --> 01:18:27,850 But that gives me back two times u minus one is u, 1152 01:18:27,850 --> 01:18:30,300 therefore, we conclude that u is two. 1153 01:18:30,300 --> 01:18:31,830 And this actually is true. 1154 01:18:31,830 --> 01:18:33,910 There's no problem like that. 1155 01:18:33,910 --> 01:18:38,540 But supposing I did something different. 1156 01:18:38,540 --> 01:18:39,740 Supposing I start up with something which 1157 01:18:39,740 --> 01:18:41,470 manifestly has no sum. 1158 01:18:41,470 --> 01:18:47,390 v is one, plus two, plus four, plus 8, plus dot, dot, dot. 1159 01:18:47,390 --> 01:18:49,560 Well, v minus one is surely two, plus four, plus eight, 1160 01:18:49,560 --> 01:18:52,010 plus dot, dot, dot. 1161 01:18:52,010 --> 01:18:57,410 v minus one over two, gee, that looks like v again. 1162 01:18:57,410 --> 01:19:01,070 From that I should be able to conclude that-- 1163 01:19:01,070 --> 01:19:03,070 that's also wrong, apparently. 1164 01:19:03,070 --> 01:19:04,510 v equals minus one. 1165 01:19:12,455 --> 01:19:15,280 That should be a minus one. 1166 01:19:15,280 --> 01:19:16,735 And that's certainly a false conclusion. 1167 01:19:22,000 --> 01:19:27,300 So when you play with limits, arguments that may work in one 1168 01:19:27,300 --> 01:19:30,750 case they may not work in some other case. 1169 01:19:30,750 --> 01:19:32,240 You have to be very careful. 1170 01:19:32,240 --> 01:19:35,752 The arguments have to be well formed. 1171 01:19:35,752 --> 01:19:40,790 And I don't know, in general, what the story is about 1172 01:19:40,790 --> 01:19:43,270 arguments like this. 1173 01:19:43,270 --> 01:19:46,060 We can read a pile of topology and find out. 1174 01:19:46,060 --> 01:19:49,750 But, surely, at least you understand now, why it might 1175 01:19:49,750 --> 01:19:52,230 be some meaning to the things we've been writing on the 1176 01:19:52,230 --> 01:19:53,260 blackboard. 1177 01:19:53,260 --> 01:19:56,480 And you understand what that might mean. 1178 01:19:56,480 --> 01:20:02,900 So, I suppose, it's almost about time for you to merit 1179 01:20:02,900 --> 01:20:05,720 being made a member of the grand recursive order of 1180 01:20:05,720 --> 01:20:09,320 lambda calculus hackers. 1181 01:20:09,320 --> 01:20:10,820 This is the badge. 1182 01:20:10,820 --> 01:20:14,540 Because you now understand, for example, what it says at 1183 01:20:14,540 --> 01:20:21,890 the very top, y F equals F y F. Thank you. 1184 01:20:21,890 --> 01:20:24,710 Are there any questions? 1185 01:20:24,710 --> 01:20:25,150 Yes, Lev. 1186 01:20:25,150 --> 01:20:28,250 AUDIENCE: With this, it seems that then there's no need to 1187 01:20:28,250 --> 01:20:31,330 define, as you imply, to just remember a 1188 01:20:31,330 --> 01:20:34,090 value, to apply it later. 1189 01:20:34,090 --> 01:20:35,850 Defines were kind of a side-effect it 1190 01:20:35,850 --> 01:20:36,490 seemed in the language. 1191 01:20:36,490 --> 01:20:37,075 [INTERPOSING] 1192 01:20:37,075 --> 01:20:39,300 are order dependent. 1193 01:20:39,300 --> 01:20:42,820 Does this eliminate the side-effect from the 1194 01:20:42,820 --> 01:20:43,150 [INTERPOSING] 1195 01:20:43,150 --> 01:20:46,010 PROFESSOR: The answer is, this is not the way these things 1196 01:20:46,010 --> 01:20:49,180 were implemented. 1197 01:20:49,180 --> 01:20:53,830 Define, indeed is implemented as an operation that actually 1198 01:20:53,830 --> 01:20:59,000 modifies an environment structure, changes the frame 1199 01:20:59,000 --> 01:21:03,690 that the define is executed in. 1200 01:21:03,690 --> 01:21:08,440 And there are many reasons for that, but a lot of this has to 1201 01:21:08,440 --> 01:21:11,340 do with making an interactive system. 1202 01:21:11,340 --> 01:21:14,750 What this is saying is that if you've made a system, and you 1203 01:21:14,750 --> 01:21:17,210 know you're not going to do any debugging or anything like 1204 01:21:17,210 --> 01:21:20,930 that, and you know everything there is all at once, and you 1205 01:21:20,930 --> 01:21:21,930 want to say, what is the meaning of a 1206 01:21:21,930 --> 01:21:24,090 final set of equations? 1207 01:21:24,090 --> 01:21:25,790 This gives you a meaning for it. 1208 01:21:25,790 --> 01:21:27,740 But in order to make an interactive system, where you 1209 01:21:27,740 --> 01:21:29,430 can change the meaning of one thing without changing 1210 01:21:29,430 --> 01:21:33,580 everything else, incrementally, you can't do 1211 01:21:33,580 --> 01:21:35,000 that by implementing it this way. 1212 01:21:40,990 --> 01:21:41,860 Yes. 1213 01:21:41,860 --> 01:21:44,650 AUDIENCE: Another question on your danger slide. 1214 01:21:44,650 --> 01:21:47,350 It seemed that the two examples that you gave had to 1215 01:21:47,350 --> 01:21:50,300 do with convergence and non-convergence? 1216 01:21:50,300 --> 01:21:53,380 And that may or may not have something to do with function 1217 01:21:53,380 --> 01:21:55,600 theory in a way which would lead you to think of it in 1218 01:21:55,600 --> 01:21:59,710 terms of linear systems, or non-linear systems. How does 1219 01:21:59,710 --> 01:22:03,140 this convergence relate to being able to see a priori 1220 01:22:03,140 --> 01:22:05,430 what properties of that might be violated? 1221 01:22:05,430 --> 01:22:07,680 PROFESSOR: I don't know. 1222 01:22:07,680 --> 01:22:10,610 The answer is, I don't know under what circumstances. 1223 01:22:10,610 --> 01:22:13,660 I don't know how to translate that into less than an 1224 01:22:13,660 --> 01:22:16,910 hour of talk more. 1225 01:22:16,910 --> 01:22:19,850 What are the conditions under which, for which we know that 1226 01:22:19,850 --> 01:22:22,720 these things converge? 1227 01:22:22,720 --> 01:22:25,230 And v, all that was telling you that arguments that are 1228 01:22:25,230 --> 01:22:30,420 based on convergence are flaky if you don't know the 1229 01:22:30,420 --> 01:22:32,810 convergence beforehand. 1230 01:22:32,810 --> 01:22:34,440 You can make wrong arguments. 1231 01:22:34,440 --> 01:22:37,810 You can make deductions, as if you know the answer, and not 1232 01:22:37,810 --> 01:22:40,690 be stopped somewhere by some obvious contradiction. 1233 01:22:40,690 --> 01:22:43,635 AUDIENCE: So can we say then that if F is a convergent 1234 01:22:43,635 --> 01:22:46,230 mathematical expression, then the recursion 1235 01:22:46,230 --> 01:22:47,690 property can be-- 1236 01:22:47,690 --> 01:22:52,740 PROFESSOR: Well, I think there's a technical kind of F, 1237 01:22:52,740 --> 01:22:55,150 there is a technical description of those F's that 1238 01:22:55,150 --> 01:23:00,790 have the property that when you iteratively apply them 1239 01:23:00,790 --> 01:23:03,020 like this, you converge. 1240 01:23:03,020 --> 01:23:08,470 Things that are monotonic, and continuous, and 1241 01:23:08,470 --> 01:23:09,370 I forgot what else. 1242 01:23:09,370 --> 01:23:12,010 There is a whole bunch of little conditions like that 1243 01:23:12,010 --> 01:23:13,430 which have this property. 1244 01:23:13,430 --> 01:23:15,820 Now the real problem is deducing from looking at the 1245 01:23:15,820 --> 01:23:19,020 F, its definition here, whether not it has those 1246 01:23:19,020 --> 01:23:22,010 properties, and that's very hard. 1247 01:23:22,010 --> 01:23:23,280 The properties are easy. 1248 01:23:23,280 --> 01:23:24,580 You can write them down. 1249 01:23:24,580 --> 01:23:26,930 You can look in a book by Joe Stoy. 1250 01:23:26,930 --> 01:23:28,660 It's a great book-- 1251 01:23:28,660 --> 01:23:29,910 Stoy. 1252 01:23:31,780 --> 01:23:37,360 It's called, The Scott-Strachey Method of 1253 01:23:37,360 --> 01:23:41,800 Denotational Semantics, and it's by Joe Stoy, MIT Press. 1254 01:23:47,960 --> 01:23:50,630 And he works out all this in great detail, enough to 1255 01:23:50,630 --> 01:23:51,880 horrify you. 1256 01:23:55,080 --> 01:23:56,330 But it really is readable. 1257 01:24:09,150 --> 01:24:11,490 OK, well, thank you. 1258 01:24:11,490 --> 01:24:13,780 Time for the bigger break, I suppose.