8715a946 |
1 | * form |
2 | * "(function element0 ...)" |
3 | * building blocks of racket semantics |
4 | ** booleans |
5 | * "(zero? 1)" "(zero? (sub1 1))" |
6 | ** symbols |
7 | * a-z+-/*=<>?!_^ |
8 | * (symbol=? 'foo 'FoO) true or false? |
9 | ** numbers |
10 | * "(expt 53 53)" "(= (/ 4 6) 2/3 (/ 2 3))" "(= (/ 4.0 6) 0.6666666666666666)" |
11 | * numbers like 4.0 are floating point numbers |
12 | * irrational numbers |
13 | ** strings |
14 | * "tutti frutti" |
15 | * (= (string-append "tutti" "frutti") "tuttifrutti") |
16 | * (= (string-append "tutti" " " "frutti") "tutti frutti") |
17 | * substring, string-ref, string=? |
18 | ** lists |
19 | * super duper important in racket |
20 | *** cons cells |
21 | * (= (list 1 2) (cons 2 (cons 3 empty))) |
22 | * same as linked lists in other languages |
23 | **** functions for cons cells |
24 | * (= (cons 1 2) '(1 . 2)) |
25 | * (define cell (cons 'a 'b)) (= (car cell) 'a) (= (cdr cell) 'b) |
26 | *** lists and list functions |
27 | * (= '() empty (list)) |
28 | **** cons function |
29 | * (= (cons 'chicken empty) '(chicken)) |
30 | * empty is used to terminate lists in racket, so '(chicken) has |
31 | an implicit empty |
32 | * what do you get when you add a chicken to an empty list? a list with |
33 | a chicken in it |
34 | * (= (cons 'pork '(beef chicken)) '(pork beef chicken)) |
35 | * (= (cons 'beef (cons 'chicken '())) '(beef chicken)) |
36 | * (= (cons 'pork (cons 'beef (cons 'chicken '()))) |
37 | '(pork beef chicken)) |
38 | **** list function |
39 | * (= (list 'pork 'beef 'chicken) '(pork beef chicken)) |
40 | **** first and rest functions |
41 | * (= (first (cons 'pork (cons 'beef (cons 'chicken empty)))) 'pork) |
42 | * (= (rest (list 'pork 'beef 'chicken)) '(beef chicken)) |
43 | * (= (first (rest ('pork beef chicken))) 'beef) |
44 | * how do you get the third item? |
45 | * what happens when you try to get the fourth item? |
46 | **** nested lists |
47 | * (= (list 'cat (list 'duck 'bat) 'ant) '(cat (duck bat) ant)) |
48 | * all lists are made of cons cells |
49 | * (= (first '((peas carrots tomatoes) (pork beef chicken))) |
50 | (peas carrots tomatoes)) |
51 | * (= (rest '(peas carrots tomatoes)) '(carrots tomatoes)) |
52 | * (= (rest (first '((peas carrots tomatoes) (pork beef chicken)))) |
53 | '(carrots tomatoes)) |
54 | * second third ... tenth built-in |