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