(define title "Structure from Chaos") #| STRUCTURE from CHAOS ==================== You are simultaneously learning many things: - a foreign language: Beginning Student Language, which comes with + vocabulary: define, cond, define-struct, cartesian-x + grammar: (define (f x) (+ (* 5 x) 22)) + meaning: the above is a function definition + idioms: (define COLOR 'red), how to arrange functions - domain knowledge: the stuff we want programs to run on + mathematics + display rate for making movies + basic physics facts + accounting + game rules + ... - computing knowledge: how does the "man in the machine" cope + rules of arithmetic for symbols, strings, images, and numbers + rules of function application: plug in argument for parameter + rules of conditional computing - design of programs (computational problem solving) %% ----------------------------------------------------------------------------- What's important? --> design 1. All languages are fashion (though some languages are more equal than others). 2. Vocabulary and grammar are "rote learning" things and, while you should be really good at that eventually for some two languages, it's too early. Look up "-->manuals" in Help Desk and see what functions there are and what grammar rules there are. 3. Domain knowledge is important. Often it's about mathematics, sometimes it's about music, and other times it's really about cooking. Have a hobby. Make sure you know how to study some area in depth. If you want to be really good and fashionable, make sure you understand how software interacts with "hard" things (wires, walls, tvs, etcetc). 4. The rules of computing are a must if you want to understand what your program does when it creates 1,000,000 pictures or calculates the 1,000,000th prime. 5. The key ideas you will take away from this course is "systematic problem solving." It'll help you with business (courses), engineering, mathematics, English, journalism, medicine, and other things. Promised. And there is no other place where you can learn it. %% ----------------------------------------------------------------------------- THE GRID: forms of data ============= | "atomic" | "enumerations" | "structure" process steps | numbers, images, ... | intervals, symbols | define-struct ===============------------------------------------------------------------------- | | [1,3] (1,3) [1,3) | (make-posn 3 4) describe data | Number Image | color is one of: .. | (make-dst "h") ---------------------------------------------------------------------------------- contract | Number -> Image | XYZ -> Number | ABC -> String purpose | create sq of size s | convert into number | add "Dear" to name ---------------------------------------------------------------------------------- functional | 3 |---> [] | [1,3] |---> 2 | (make-posn 3 4) examples | .... | ... | |--> "5" ---------------------------------------------------------------------------------- template | domain knowledge | cond cases! | extractor expr. ---------------------------------------------------------------------------------- now code ---------------------------------------------------------------------------------- tests | turn examples into tests (use of equal?) | (equal? (S 3) []) | (equal? (f 1 3) 2) | (equal? 5 | | | (f (make-posn 3 4))) On Computer, demonstrate how to use the above %% ============================================================================= EXAMPLE 1: Design a function that converts Celsius degrees into Fahrenheit. 1. Represent temperatures with numbers. 2a. convert : Number -> Number 2b. consumes a number representing Celsius temp and computes equivalent Fahrenheit 3. TABLE given: 0 | 100 | -40 ... wanted: 32 | 212 | -40 ... DOMAIN KNOWLEDGE: physics, chemistry, wikipedia 4. (define (convert c) ...) ;; PURE DOMAIN KNOWLEDGE 5. (define (convert c) (+ (* 9/5 c) 32)) 6. (equal? (convert 0) 32) (equal? (convert 100) 212) (equal? (convert -40) -40) expect to see 3 x true %% ============================================================================= EXAMPLE 2: Design a data representation for the titles that airlines use to address people: Dr., Mr., Mstr., Ms., Mrs., Miss. (These are just some not all.) #| A title is one of: -- 'Dr. -- 'Mr. -- 'Mstr. -- 'Ms -- 'Mrs. -- 'Miss |# Design the function union-rule-457, which counts the number of keystrokes a typist must make to enter a title into a computer. Don't forget the RETURN key. 1. Titles are as above. 2. union-rule-457 : Title -> Number count the number of ... 3. 'Dr. |--> 4 (3 + 1) 'Miss |--> 5 4. (define (union-rule-457 t) (cond [(symbol=? t 'Dr.) ...] ...)) AS MANY COND clauses as DATA clauses. |#