forked from DeathKing/Learning-SICP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec5b_512kb.mp4.srt
5177 lines (3966 loc) · 80 KB
/
lec5b_512kb.mp4.srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
0
00:00:00,000 --> 00:00:21,170
1
00:00:21,170 --> 00:00:24,550
PROFESSOR: Well, now that we've
given you some power to
2
00:00:24,550 --> 00:00:28,340
make independent local state
and to model objects, I
3
00:00:28,340 --> 00:00:31,610
thought we'd do a bit of
programming of a very
4
00:00:31,610 --> 00:00:35,380
complicated kind, just to
illustrate what you can do
5
00:00:35,380 --> 00:00:36,630
with this sort of thing.
6
00:00:36,630 --> 00:00:40,430
7
00:00:40,430 --> 00:00:44,080
I suppose, as I said, we were
motivated by physical systems
8
00:00:44,080 --> 00:00:47,200
and the ways we like to think
about physical systems, which
9
00:00:47,200 --> 00:00:52,060
is that there are these things
that the world is made out of.
10
00:00:52,060 --> 00:00:55,570
And each of these things has
particular independent local
11
00:00:55,570 --> 00:00:58,830
state, and therefore
it is a thing.
12
00:00:58,830 --> 00:01:01,280
That's what makes it a thing.
13
00:01:01,280 --> 00:01:04,410
And then we're going to say
that in the model in the
14
00:01:04,410 --> 00:01:07,900
world--we have a world and a
model in our minds and in the
15
00:01:07,900 --> 00:01:10,940
computer of that world.
16
00:01:10,940 --> 00:01:13,230
And what I want to make is a
correspondence between the
17
00:01:13,230 --> 00:01:15,980
objects in the world and the
objects in the computer, the
18
00:01:15,980 --> 00:01:18,140
relationships between the
objects in the world and the
19
00:01:18,140 --> 00:01:21,200
relationships between those same
obj...--the model objects
20
00:01:21,200 --> 00:01:24,890
in the computer, and the
functions that relate things
21
00:01:24,890 --> 00:01:27,320
in the world to the functions
that relate
22
00:01:27,320 --> 00:01:28,570
things in the computer.
23
00:01:28,570 --> 00:01:30,840
24
00:01:30,840 --> 00:01:34,740
This buys us modularity.
25
00:01:34,740 --> 00:01:37,786
If we really believe the world
is like that, that it's made
26
00:01:37,786 --> 00:01:40,120
out of these little pieces, and
of course we could arrange
27
00:01:40,120 --> 00:01:43,085
our world to be like that, we
could only model those things
28
00:01:43,085 --> 00:01:47,030
that are like that, then we can
inherit the modularity in
29
00:01:47,030 --> 00:01:50,450
the world into our
programming.
30
00:01:50,450 --> 00:01:53,150
That's why we would invent some
of this object-oriented
31
00:01:53,150 --> 00:01:55,420
programming.
32
00:01:55,420 --> 00:01:58,890
Well, let's take the best
kind of objects I know.
33
00:01:58,890 --> 00:02:03,160
They're completely--they're
completely wonderful:
34
00:02:03,160 --> 00:02:10,270
electrical systems. Electrical
systems really are the
35
00:02:10,270 --> 00:02:14,220
physicist's best,
best objects.
36
00:02:14,220 --> 00:02:16,760
You see over here I have some
piece of machinery.
37
00:02:16,760 --> 00:02:20,040
Right here's a piece
of machinery.
38
00:02:20,040 --> 00:02:24,270
And it's got an electrical wire
connecting one part of
39
00:02:24,270 --> 00:02:27,190
the machinery with another
part of the machinery.
40
00:02:27,190 --> 00:02:30,450
And one of the wonderful
properties of the electrical
41
00:02:30,450 --> 00:02:34,610
world is that I can say this is
an object, and this is an
42
00:02:34,610 --> 00:02:36,040
object, and they're--
43
00:02:36,040 --> 00:02:38,310
the connection between
them is clear.
44
00:02:38,310 --> 00:02:41,190
In principle, there is no
connection that I didn't
45
00:02:41,190 --> 00:02:44,740
describe with these wires.
46
00:02:44,740 --> 00:02:48,000
Let's say if I have light bulbs,
a light bulb and a
47
00:02:48,000 --> 00:02:51,370
power supply that's plugged
into the outlet.
48
00:02:51,370 --> 00:02:53,620
Then the connection is
perfectly clear.
49
00:02:53,620 --> 00:02:56,220
There's no other connections
that we know of.
50
00:02:56,220 --> 00:02:59,250
If I were to tie a knot in the
wire that connects the light
51
00:02:59,250 --> 00:03:04,040
bulb to the power supply, the
light remains lit up.
52
00:03:04,040 --> 00:03:05,290
It doesn't care.
53
00:03:05,290 --> 00:03:08,300
54
00:03:08,300 --> 00:03:11,120
That the way the physics is
arranged is such that the
55
00:03:11,120 --> 00:03:13,790
connection can be made abstract,
at least for low
56
00:03:13,790 --> 00:03:15,270
frequencies and things
like that.
57
00:03:15,270 --> 00:03:17,840
58
00:03:17,840 --> 00:03:20,360
So in fact, we have captured all
of the connections there
59
00:03:20,360 --> 00:03:22,350
really are.
60
00:03:22,350 --> 00:03:24,310
Well, as you can go one step
further and talk about the
61
00:03:24,310 --> 00:03:27,830
most abstract types of
electrical systems we have,
62
00:03:27,830 --> 00:03:30,951
digital to dual circuits.
63
00:03:30,951 --> 00:03:34,610
And here there are certain
kinds of objects.
64
00:03:34,610 --> 00:03:38,240
For example, in digital
circuits we
65
00:03:38,240 --> 00:03:41,092
have things like inverters.
66
00:03:41,092 --> 00:03:43,990
We have things like and-gates.
67
00:03:43,990 --> 00:03:47,210
We have things like or-gates.
68
00:03:47,210 --> 00:03:53,980
We connect them together by
sort-of wires which represent
69
00:03:53,980 --> 00:03:55,610
abstract signals.
70
00:03:55,610 --> 00:03:57,390
We don't really care as physical
variables whether
71
00:03:57,390 --> 00:04:00,190
these are voltages or currents
or some combination or
72
00:04:00,190 --> 00:04:05,160
anything like that, or water,
water pressure.
73
00:04:05,160 --> 00:04:09,420
These abstract variables
represent certain signals.
74
00:04:09,420 --> 00:04:11,950
And we build systems by
wiring these things
75
00:04:11,950 --> 00:04:14,070
together with wires.
76
00:04:14,070 --> 00:04:17,730
So today what I'm going to show
you, right now, we're
77
00:04:17,730 --> 00:04:22,650
going to build up an invented
language in Lisp, embedded in
78
00:04:22,650 --> 00:04:24,590
the same sense that Henderson's
picture language
79
00:04:24,590 --> 00:04:29,780
was embedded, which is not the
same sense as the language of
80
00:04:29,780 --> 00:04:32,700
pattern match and substitution
was done yesterday.
81
00:04:32,700 --> 00:04:35,725
The pattern match/substitution
language was interpreted by a
82
00:04:35,725 --> 00:04:38,160
Lisp program.
83
00:04:38,160 --> 00:04:40,920
But the embedding of Henderson's
program is that we
84
00:04:40,920 --> 00:04:43,370
just build up more and more
procedures that encapsulate
85
00:04:43,370 --> 00:04:45,480
the structure we want.
86
00:04:45,480 --> 00:04:49,280
So for example here, I'm going
to have some various primitive
87
00:04:49,280 --> 00:04:53,026
kinds of objects, as you see,
that one and that one.
88
00:04:53,026 --> 00:04:55,810
I'm going to use wires
to combine them.
89
00:04:55,810 --> 00:04:58,420
The way I represent
attaching--
90
00:04:58,420 --> 00:04:59,870
I can make wires.
91
00:04:59,870 --> 00:05:01,740
So let's say A is a wire.
92
00:05:01,740 --> 00:05:02,690
And B is a wire.
93
00:05:02,690 --> 00:05:03,460
And C is a wire.
94
00:05:03,460 --> 00:05:04,230
And D is a wire.
95
00:05:04,230 --> 00:05:04,830
And E is wire.
96
00:05:04,830 --> 00:05:06,880
And S is a wire.
97
00:05:06,880 --> 00:05:12,380
Well, an or-gate that has both
inputs, the inputs being A and
98
00:05:12,380 --> 00:05:17,940
B, and the output being Y or
D, you notate like this.
99
00:05:17,940 --> 00:05:22,390
An and-gate, which has inputs
A and B and output C, we
100
00:05:22,390 --> 00:05:24,820
notate like that.
101
00:05:24,820 --> 00:05:29,690
By making such a sequence of
declarations, like this, I can
102
00:05:29,690 --> 00:05:32,750
wire together an arbitrary
circuit.
103
00:05:32,750 --> 00:05:35,940
So I've just told you a set
of primitives and means of
104
00:05:35,940 --> 00:05:40,930
combination for building digital
circuits, when I need
105
00:05:40,930 --> 00:05:43,690
more in a real language
than abstraction.
106
00:05:43,690 --> 00:05:46,766
And so for example,
here I have--here
107
00:05:46,766 --> 00:05:52,240
I have a half adder.
108
00:05:52,240 --> 00:05:54,270
It's something you all
know if you've
109
00:05:54,270 --> 00:05:56,930
done any digital design.
110
00:05:56,930 --> 00:06:00,830
It's used for adding numbers
together on A and B and
111
00:06:00,830 --> 00:06:03,956
putting out a sum and a carry.
112
00:06:03,956 --> 00:06:05,710
And in fact, the wiring
diagram is
113
00:06:05,710 --> 00:06:07,450
exactly what I told you.
114
00:06:07,450 --> 00:06:11,410
A half adder with things that
come out of the box-- you see
115
00:06:11,410 --> 00:06:14,790
the box, the boundary, the
abstraction is always a box.
116
00:06:14,790 --> 00:06:19,700
And there are things that come
out of it, A, B, S, and C.
117
00:06:19,700 --> 00:06:24,950
Those are the declared
variables--declared variables
118
00:06:24,950 --> 00:06:27,020
of a lambda expression,
which is the one that
119
00:06:27,020 --> 00:06:28,270
defines half adder.
120
00:06:28,270 --> 00:06:31,400
121
00:06:31,400 --> 00:06:36,080
And internal to that, I make up
some more wires, D and E,
122
00:06:36,080 --> 00:06:37,760
which I'm going to use for
the interconnect--
123
00:06:37,760 --> 00:06:41,860
here E is this one and D is this
wire, the interconnect
124
00:06:41,860 --> 00:06:45,100
that doesn't come through
the walls of the box--
125
00:06:45,100 --> 00:06:48,790
and wire things together
as you just saw.
126
00:06:48,790 --> 00:06:51,180
And the nice thing about this
that I've just shown you is
127
00:06:51,180 --> 00:06:53,890
this language is hierarchical
in the right way.
128
00:06:53,890 --> 00:06:55,950
If a language isn't hierarchical
in the right way,
129
00:06:55,950 --> 00:06:58,850
if it turns out that a compound
object doesn't look
130
00:06:58,850 --> 00:07:00,820
like a primitive, there's
something
131
00:07:00,820 --> 00:07:02,180
wrong with the language--
132
00:07:02,180 --> 00:07:06,300
at least the way I
feel about that.
133
00:07:06,300 --> 00:07:09,220
So here we have--here, instead
of starting with mathematical
134
00:07:09,220 --> 00:07:10,900
functions, or things that
compute mathematical
135
00:07:10,900 --> 00:07:13,870
functions, which is what we've
been doing up until now,
136
00:07:13,870 --> 00:07:15,770
instead of starting with
things that look like
137
00:07:15,770 --> 00:07:18,080
mathematical functions, or
compute such things, we are
138
00:07:18,080 --> 00:07:21,330
starting with things that are
electrical objects and we
139
00:07:21,330 --> 00:07:23,350
build up more electrical
objects.
140
00:07:23,350 --> 00:07:26,590
And the glue we're using
is basically the
141
00:07:26,590 --> 00:07:30,500
Lisp structure: lambdas.
142
00:07:30,500 --> 00:07:32,930
Lambda is the ultimate
glue, if you will.
143
00:07:32,930 --> 00:07:39,000
And of course, half adder itself
can be used in a more
144
00:07:39,000 --> 00:07:42,250
complicated abstraction called
a full adder, which in fact
145
00:07:42,250 --> 00:07:46,670
involves two half adders, as you
see here, hooked together
146
00:07:46,670 --> 00:07:50,600
with some extra wires, that you
see here, S, C1, and C2,
147
00:07:50,600 --> 00:07:57,340
and an or-gate, to manufacture
a full adder, which takes a
148
00:07:57,340 --> 00:08:01,570
input number, another input
number, a carry in, and
149
00:08:01,570 --> 00:08:05,900
produces output, a sum
and a carry out.
150
00:08:05,900 --> 00:08:09,820
And out of full adders, you can
make real adder chains and
151
00:08:09,820 --> 00:08:12,990
big adders.
152
00:08:12,990 --> 00:08:18,870
So we have here a language so
far that has primitives, means
153
00:08:18,870 --> 00:08:22,270
of combination, and means of
abstraction to real language.
154
00:08:22,270 --> 00:08:25,000
Now, how are we going
to implement this?
155
00:08:25,000 --> 00:08:27,070
Well, let's do it easily.
156
00:08:27,070 --> 00:08:28,610
Let's look at the primitives.
157
00:08:28,610 --> 00:08:31,160
The only problem is we have to
implement the primitives.
158
00:08:31,160 --> 00:08:34,270
Nothing else has to be
implemented, because we're
159
00:08:34,270 --> 00:08:37,640
picking up the means of
combination and abstraction
160
00:08:37,640 --> 00:08:43,417
from Lisp, inheriting them
in the embedding.
161
00:08:43,417 --> 00:08:45,860
OK, so let's look at a
particular primitive.
162
00:08:45,860 --> 00:08:47,400
An inverter is a nice one.
163
00:08:47,400 --> 00:08:51,540
164
00:08:51,540 --> 00:08:54,900
Now, inverter has two wires
coming in, an in and an out.
165
00:08:54,900 --> 00:08:57,440
166
00:08:57,440 --> 00:09:01,570
And somehow, it's going to have
to know what to do when a
167
00:09:01,570 --> 00:09:04,300
signal comes in.
168
00:09:04,300 --> 00:09:07,710
So somehow it's going to have
to tell its input wire--
169
00:09:07,710 --> 00:09:10,756
and now we're going to talk
about objects and we're going
170
00:09:10,756 --> 00:09:13,260
to see this in a little
more detail soon--
171
00:09:13,260 --> 00:09:16,660
but it's going to have to tell
its input wire that when you
172
00:09:16,660 --> 00:09:20,120
change, tell me.
173
00:09:20,120 --> 00:09:22,720
So this object, the object which
is the inverter has to
174
00:09:22,720 --> 00:09:25,070
tell the object which
is the input wire,
175
00:09:25,070 --> 00:09:26,870
hi, my name is George.
176
00:09:26,870 --> 00:09:30,480
And my, my job is to do
something with results when
177
00:09:30,480 --> 00:09:31,720
you change.
178
00:09:31,720 --> 00:09:34,730
So when you change, you get a
change, tell me about it.
179
00:09:34,730 --> 00:09:37,010
Because I've got to do
something with that.
180
00:09:37,010 --> 00:09:42,200
Well, that's done down here by
adding an action on the input
181
00:09:42,200 --> 00:09:47,020
wire called invert-in, where
invert-in is defined over here
182
00:09:47,020 --> 00:09:51,660
to be a procedure of no
arguments, which gets the
183
00:09:51,660 --> 00:09:56,130
logical not of the signal
on the input wire.
184
00:09:56,130 --> 00:09:59,720
And after some delay, which is
the inverter delay, all these
185
00:09:59,720 --> 00:10:04,110
electrical objects have delays,
we'll do the following
186
00:10:04,110 --> 00:10:07,140
thing-- set the signal on the
output wire to the new value.
187
00:10:07,140 --> 00:10:10,160
188
00:10:10,160 --> 00:10:12,400
A very simple program.
189
00:10:12,400 --> 00:10:14,820
Now, you have to imagine that
the output wire has to be
190
00:10:14,820 --> 00:10:19,650
sensitive and know that when
its signal changes, it may
191
00:10:19,650 --> 00:10:23,840
have to tell other guys,
hey, wake up.
192
00:10:23,840 --> 00:10:26,050
My value has changed.
193
00:10:26,050 --> 00:10:29,350
So when you hook together
inverter with an and-gate or
194
00:10:29,350 --> 00:10:31,680
something like that, there has
to be a lot of communication
195
00:10:31,680 --> 00:10:34,040
going on in order to
make sure that the
196
00:10:34,040 --> 00:10:36,810
signal propagates right.
197
00:10:36,810 --> 00:10:38,620
And down here is nothing
very exciting.
198
00:10:38,620 --> 00:10:41,100
This is just the definition
of logical not for some
199
00:10:41,100 --> 00:10:44,170
particular representations
of the logical values--
200
00:10:44,170 --> 00:10:46,240
1, 0 in this case.
201
00:10:46,240 --> 00:10:49,780
And we can look at things more
complicated like and-gates.
202
00:10:49,780 --> 00:10:55,000
And-gates take two inputs, A1
and A2, we'll call them, and
203
00:10:55,000 --> 00:10:56,950
produce an output.
204
00:10:56,950 --> 00:10:59,840
But the structure of the
and-gate is identical to the
205
00:10:59,840 --> 00:11:00,860
one we just saw.
206
00:11:00,860 --> 00:11:03,000
There's one called an and-action
procedure that's
207
00:11:03,000 --> 00:11:08,570
defined, which is the thing that
gets called when an input
208
00:11:08,570 --> 00:11:10,910
is changed.
209
00:11:10,910 --> 00:11:13,230
And what it does, of course, is
nothing more than compute
210
00:11:13,230 --> 00:11:15,900
the logical and of the signals
on the inputs.
211
00:11:15,900 --> 00:11:20,890