;; 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 lecture_02) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ()))) ;; Fold* is: (foldl fn base list) ;; Applies the fn recursively to all elements ;; foldl: (+ 4 (+ 3 (+ 2 (+ 1 10)))) (foldl + 10 (list 1 2 3 4)) ;; foldr: (+ 1 (+ 2 (+ 3 (+ 4 0)))) (foldr + 0 (list 1 2 3 4)) ;; Map is: [X -> Y] [Listof X] -> [Listof Y] ;; i.e. (map F (list x1 x2 x3)) -> ;; (list (F x1) (F x2) (F x3)) (map (lambda (t) (+ t 5)) (list 1 2 3 4)) ;; Examples of primitive data in racket 5 "test" true 'nope ;; Compound data (list 1 2 3) ;; A Rocket is: (make-rocket String Posn Boolean) (define-struct rocket (name pos landing?)) ;; A Posn is: (make-posn Number Number) (define-struct posn (x y)) ;; Instantiation of structs (structs are very similar ;; to classes) (make-rocket 1 5 "hi") (make-posn 1 2)