From 8715a946ec60184cc9270affbf28a7302db31a3e Mon Sep 17 00:00:00 2001 From: daniel watson Date: Thu, 4 Aug 2016 09:12:22 -0700 Subject: [PATCH] take note up to first and rest functions --- notes.org | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 notes.org diff --git a/notes.org b/notes.org new file mode 100644 index 0000000..ebc40bf --- /dev/null +++ b/notes.org @@ -0,0 +1,54 @@ +* form + * "(function element0 ...)" +* building blocks of racket semantics +** booleans + * "(zero? 1)" "(zero? (sub1 1))" +** symbols + * a-z+-/*=<>?!_^ + * (symbol=? 'foo 'FoO) true or false? +** numbers + * "(expt 53 53)" "(= (/ 4 6) 2/3 (/ 2 3))" "(= (/ 4.0 6) 0.6666666666666666)" + * numbers like 4.0 are floating point numbers + * irrational numbers +** strings + * "tutti frutti" + * (= (string-append "tutti" "frutti") "tuttifrutti") + * (= (string-append "tutti" " " "frutti") "tutti frutti") + * substring, string-ref, string=? +** lists + * super duper important in racket +*** cons cells + * (= (list 1 2) (cons 2 (cons 3 empty))) + * same as linked lists in other languages +**** functions for cons cells + * (= (cons 1 2) '(1 . 2)) + * (define cell (cons 'a 'b)) (= (car cell) 'a) (= (cdr cell) 'b) +*** lists and list functions + * (= '() empty (list)) +**** cons function + * (= (cons 'chicken empty) '(chicken)) + * empty is used to terminate lists in racket, so '(chicken) has + an implicit empty + * what do you get when you add a chicken to an empty list? a list with + a chicken in it + * (= (cons 'pork '(beef chicken)) '(pork beef chicken)) + * (= (cons 'beef (cons 'chicken '())) '(beef chicken)) + * (= (cons 'pork (cons 'beef (cons 'chicken '()))) + '(pork beef chicken)) +**** list function + * (= (list 'pork 'beef 'chicken) '(pork beef chicken)) +**** first and rest functions + * (= (first (cons 'pork (cons 'beef (cons 'chicken empty)))) 'pork) + * (= (rest (list 'pork 'beef 'chicken)) '(beef chicken)) + * (= (first (rest ('pork beef chicken))) 'beef) + * how do you get the third item? + * what happens when you try to get the fourth item? +**** nested lists + * (= (list 'cat (list 'duck 'bat) 'ant) '(cat (duck bat) ant)) + * all lists are made of cons cells + * (= (first '((peas carrots tomatoes) (pork beef chicken))) + (peas carrots tomatoes)) + * (= (rest '(peas carrots tomatoes)) '(carrots tomatoes)) + * (= (rest (first '((peas carrots tomatoes) (pork beef chicken)))) + '(carrots tomatoes)) + * second third ... tenth built-in -- 2.30.2