; ABSTRACTION BARRIERS in functions as in data: ; I create imaginary friends, and I call them ; clouds in paradise. ; In the clouds I see something called fractions (rationals). ; They have nominators and denominators. 2B:(5m16s) ; But how to represent them? ; The strategy => 2B:(6m5s) Thinking wishfully. ; (make-rat n d) ---> a cloud containing n and d. ; (numer (make-rat n d)) ---> returns numerator. ; (denom (make-rat n d)) ---> returns denominator ; assuming that constructor and selectors are already there... 2B:(10m55s) (DEFINE (+RAT X Y) (MAKE-RAT (+ (* (NUMER X) (DENOM Y)) (* (NUMER Y) (DENOM X))) (* (DENOM X) (DENOM Y)))) (DEFINE (*RAT X Y) (MAKE-RAT (* (NUMER X) (NUMER Y)) (* (DENOM X) (DENOM Y)))) ; 2B:(15m7s) Hal Abelson packt aus! ; "Because the whole name of this GAME... is..." ; 2B:(15m50s) + important question ; BREAK 2B:(17m38) ; List Structures ; ==> PAIRS ; (cons x y) ; constructs a pair whose first part ; is x and whose second part is y ; (car p) ; selects the first part of the pair p ; (cdr p) ; selects the second part of the pair p ; ; FOR ANY x AND y ; (car (cons x y)) ; is x ; (cdr (cons x y)) ; is y (DEFINE (MAKE-RAT N D) (CONS N D)) (DEFINE (NUMER X) (CAR X)) (DEFINE (DENOM X) (CDR X)) ; CASE-EXAMPLE 2B:(24m30s) ; 1/2 + 1/4 (DEFINE A (MAKE-RAT 1 2)) (DEFINE B (MAKE-RAT 1 4)) (DEFINE ANS (+RAT A B)) (NUMER ANS) ;=> 6 (DENOM ANS) ;=> 8 ; 2B:(26m25s) The answer should be 3/4. (resolution) ; 2B:(29m10s) Abstraction Layer (barrier) and the methology of ; seperating the USAGE from REPRESENTATION ; Hal talking about his favorite names, controlling spirits... ; abstraction; it's just magic. ; 2B:(35m55s) "You'd like to make progress, but also never want to be ; bound by the consequences of your decisisons." ; "You might not be able to decide... at the moment you're worrying ; about these numbers. -another magic-problem." ; That could be one reason, why many people have names for everything, but ; are not ready to describe something thoroughly. (Which is a good thing!) ; 2B:(37m40s) Some very good QUESTIONS! ; ==> (about religion vs magic, #[PROCEDURE LET] and tech-magazine's fantasies) ; 2B:(41m) BREAK ; Now about the question of what you can build with a given tool, which ; tries to reduce complexity. What importance do such tools play? ; -> Why do you want this reduction into just another name? ; now representing vectors in the plane: ; (define (make-vector x y) (cons x y)) ; (define (xcor p) (car p)) ; (define (ycor p) (cdr p)) ; -> Why do you want this? ; * MAKE-VECTOR is just like MAKE-RAT. ; * XCOR is just like NUMER ; * YCOR is just like DENOM ; I personally think, that this is important, because you relate something ; to NUMER. You think, that it gives you the numerator of a rational number. ; Why would you call NUMER on a vector data-type? A vector doesn't have a ; numerator. That's why you would implement the selector XCOR -- to get the ; coordinate X of a vector. It should not play a role in your mind, that ; the data-type for a vector is the same as the one for a rational number. ; Now you can use data-types to represent other data-types. 2B:(43m37s) ; (define (make-seg p q) (cons p q)) ; (define (seg-start s) (car s)) ; (define (seg-end s) (cdr s)) ; (define (midpoint s) ;now we can define operations on them 2B:(44m41s) ; (let ((a (seg-start s)) ; (b (seg-end s))) ; (make-vector ; (average (xcor a) (xcor b)) ; (average (ycor a) (ycor b))))) ; (define (length s) ; (let ; ((dx (- (xcor (seg-end s)) ; (xcor (seg-start s)))) ; (dy (- (ycor (seg-end s)) ; (ycor (seg-start s))))) ; (sqrt (+ (square dx) ; (square dy))))) ; ; Again creating ABSTRACTION BARRIERS. And again a section, where Hal ; explains why abstracting things is so important. (Talking about concepts ; like "PAIRS of PAIRS" and introducing the word "CLOSURE".) ; BREAK 2B:(56m37s) after an important question about PAIRS. ; Now describing what it all means. (AXIOM for PAIRS) ; Hal tries real hard to scare his audience this time... ; with this: ; (define (cons a b) ; (lambda (pick) ; (cond ((= pick 1) a) ; ((= pick 2) b)))) ; (define (car x) (x 1)) ; (define (cdr x) (x 2)) ; ; --> data built out of air? -my inner vacuums say yes. ; if you really believe this stuff: ; getting the hang of it... going philosophical! ; Fundamental QUESTIONS 2B:(1h10m5s) and then BREAK (END)