;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-advanced-reader.ss" "lang")((modname week8_tu) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "image.ss" "teachpack" "htdp"))))) ; rough exam format: ; - 40% multiple choice ; - 40% short answer ; - 1-2 "write a program" questions ; things to know: ; 1) evalute stuff ; example: what does the following evaluate to: (+ 5 (- 4 3)) ; => (+ 5 1) => 6 ; Answer: 6 ; know, for example, cond and if evaluation rules (define (f x) (cond [(= x 0) 1] [else (f (- x 1))])) ; exceptions to general eval rule: cond, if, define, define-struct ... ; 2) define/execute a function ; what does the following do? (define (f x) (+ x 1)) (f 5) ; (f 5) => (+ 5 1) => 6 ; 3) Design recipe ; what are the steps of the design recipe? ; data ; signature, purpose, header ; examples ; template ; body ; tests ; 4) Data definitions ; compound: ; an invention-event is a: ; - symbol inventor ; - symbol item ; - number year (define-struct invention-event (inventor item year)) ; functions we get: ; (make-invention-event ...), (invention-event? ...) ; selectors: (invention-event-inventor ...), etc. ; conditional: ; a list-of-numbers is either: ; - empty, or ; - (cons number list-of-numbers) ; 5) Templates ; Know how to generate templates for conditional and compound data. ; compound: ;(define (fun-for-ie ie) ; ( ... (invention-event-inventor ie) ... ; ... (invention-event-item ie) ... ; ... (invention-event-year ie) ...) ; conditional: ; (define (fun-for-lon lon) ; (cond [(empty? lon) ...] ; [(cons? lon) ; (...(first lon)...(fun-for-lon (rest lon))...)] ; )) ; 6) Recursion ; structural (as in fun-for-lon above) ; know: ; lists ; trees ; generative ; know about: ; base cases ; infinite recursion ; 7) Binary search trees ; example question: given 5 nodes, draw the corresponding BST. ; know how to find nodes within a BST ; 8) Local ; Know what it means ; example question, what does the following evaluate to? (define (g x) (local [(define (g y) (+ x 4))] (g 3))) (g 5) ; 9) lambda ; know how to define functions with lambda and pass as args, return from functions ; example: write a function "fun-to-add-x" that returns a function ; that will add a passed-in value x to a number input ; fun-to-add-x : number -> (number -> number) (define (fun-to-add-x x) (lambda (y) (+ y x))) ; 10) map/filter ; example: write an expression that negates all numbers in a list of numbers lon1 (map (lambda (x) (- x)) lon1) ;or (map - lon1) ; 11) Signatures: ; what's the signature for map? ; map: (X -> Y) list-of-X -> list-of-Y ; know how to write signatures with variables and functions as arguments