Wednesday, January 22, 2014

Introductory Comp Sci class 1986 Style...

Wow, I didn't realize that this series from MIT was recorded in the stone age. I'm going to stick with it for now, partially out of morbid curiosity and partially because I figure maybe if I'm using a more basic tool set I can focus more on the concepts and not get so distracted by the gadgetry.  On the flip side, the chances of me ever using LISP for anything are basically NIL. For now I'll take a wait and see approach.  I think the format I'm going to use for these lecture video posts is to post a few thoughts and then dump my notes.

Couple notes on the use of MIT/GNU Scheme: Ctrl+x then Ctrl+e to evaluate a line of code in the interpreter... had a hell of a time finding that in the documentation.  Also, if you want decimals, put a period at the end of a number. Notice the difference here:





So here is the note dump: (note to self... no more bullet lists in future note taking... shoot me in the face!)

  • Computer science isn’t science, it’s magic
  • Computer science isn’t so much about the tools (computers)
  • Formalize intuitions about process, how to do things
  • Declarative knowledge (what is, mathematics) vs imperative knowledge (how to do something)
  • Procedure is a pattern of rules that control a process
  • techniques for controlling the complexity of a  large system - what this course (and COSC) is really about.
  • Software is not bound by the same constraints as physical systems - idealized, abstract “parts”
  • Black box abstraction - suppress detail, hide internals
    • Primitive Objects - Procedures and data
    • Means of combination
    • Means of abstraction
    • Capturing common patterns
  • Conventional Interfaces - agreed upon ways of plugging together components
    • Generic operations
    • Large scale structures and modularity
    • Object oriented programming
    • Operations on aggregates - streams
  • Metalinguistic Abstraction - Making new languages 
    • apply - eval loop in LISP
    • Logical programming
    • Register machines
  • Things to know about a language
    • What are the primitive elements
    • How can they be combined
    • Means of abstraction
LISP:
Polish notation: add 1 and 2: (+ 1 2)
Define operator used for abstraction
(define (square x) (* x x))
Lambda operator is for “make a procedure)
(define square (lambda (x) (* x x)))
“Syntactic sugar” - top syntax simpler for human reader.

evaluating the value of just a defined procedure returns [COMPOUND-PROCEDURE X]

Case analysis of absolute value function. Uses “cond” operator:
(define (abs x) 
(cond ((< x 0)(-x) 
(= x 0)(0) 
(> x 0)(x))))
Alternate form
(define (abs x)
(if (< x 0) (-x) x))

Compares to Basic and FORTRAN, lack of for loop or do...while loop in LISP

Implement Heron of Alexandria algorithm to guess square root of x
(define (try guess x)
(if (good-enough? guess x)
guess
(try (improve guess x) x)))

(define (sqrt x) (try 1 x))

(define (improve guess x)
(average guess (/ x guess)))

(define (good-enough? guess x)
(< (abs (- (square guess) x))
.001))

Recursion ftw!

Block structure - package internals inside a definition. Above example, “try”, “good-enough?”, and “improve” are all hidden outside the sqrt procedure.


No comments:

Post a Comment