💾 Archived View for gemini.lostleonardo.xyz › sicp › lecture-5B.gmi captured on 2022-06-03 at 23:08:28. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-11-30)
-=-=-=-=-=-=-
Independent local state allows you to model objects. This buys us modularity. That is why we would invent some of this object-oriented programming.
"We have world and we have model in our minds and in the computer of that world, and what I want to make is correspondence between the objects in the world and the objects in the computer, and the relationships between those objects in the world and the relationships between the model objects in the computer, and the functions that relate things in the world and the functions that relate things in the computer".
Embedding a language in Lisp is about building up more and more procedures that encapsulate the structure that we want.
The abstraction is always a box. The things that come out of it are the declared variables that make up the procedure.
This language is hierarchical in the right way. "If turns out that a compound object does not look like a primitive then there is something wrong with the language".
The glue we are using is the Lisp structure - lambdas - lambda is the ultimate glue, if you will.
When you create a language like this, all that you need to implement are the primitives, because you are picking up the means of combination and the means of abastraction from Lisp, inheriting them as part of the embedding.
Procedures have access to all of the variables bound in their environment throughout the lifetime of that procedure.
"We have been making a simulation. The simulation is an event-driven simulation where the objects in the world are the objects in the computer and the changes in state that are happening in the world in time are organised in time in the computer".
Assignment statements are used when you have events that happen one after another, in order.
Agendas are a way of organising events in time.
---
Conses have an identity
(DEFINE a (CONS 1 2 )) - somewhere in some environment I have made a symbol 'a with a value that is a pair consisting of a pointer to a 1 and a pointer to a 2
(DEFINE b (CONS a a)) - in another environemnt I have made another pair (identified by the symbol 'b) and it contains two pointers to a
At this point I have three names for this object - a, car of a and car of b. In other words, the object has several aliases.
"Inadvertent sharing, unanticipated interactions between objects is the source of most of the bugs that appear in complicated programs"
"By introducing the possibility of identity, sharing and aliasing, we get a lot of power, but we have to pay with it, with a lot of complexity and bugs"
---
Alonzo Church's Hack
This is cool stuff, but I'm not sure I can follow it.
(define (cons x y)
(lambda (m) (m x y)))
(define (car x)
(x (lambda (a d) a)))
(define (cdr x)
(x (lamdba (a d) d)))
---
"In principle, once I have introduced one assignment operator, I have introduced them all".