replace = with equal? where necessary
[ozzloy@gmail.com/realm-of-racket-journey] / notes.org
CommitLineData
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"
af8e2df9 15 * (equal? (string-append "tutti" "frutti") "tuttifrutti")
16 * (equal?(string-append "tutti" " " "frutti") "tutti frutti")
8715a946 17 * substring, string-ref, string=?
18** lists
19 * super duper important in racket
20*** cons cells
af8e2df9 21 * (equal?(list 1 2) (cons 2 (cons 3 empty)))
8715a946 22 * same as linked lists in other languages
23**** functions for cons cells
af8e2df9 24 * (equal?(cons 1 2) '(1 . 2))
25 * (define cell (cons 'a 'b)) (equal?(car cell) 'a) (equal?(cdr cell) 'b)
8715a946 26*** lists and list functions
af8e2df9 27 * (equal?'() empty (list))
8715a946 28**** cons function
af8e2df9 29 * (equal?(cons 'chicken empty) '(chicken))
8715a946 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
af8e2df9 34 * (equal?(cons 'pork '(beef chicken)) '(pork beef chicken))
35 * (equal?(cons 'beef (cons 'chicken '())) '(beef chicken))
36 * (equal?(cons 'pork (cons 'beef (cons 'chicken '())))
8715a946 37 '(pork beef chicken))
38**** list function
af8e2df9 39 * (equal?(list 'pork 'beef 'chicken) '(pork beef chicken))
8715a946 40**** first and rest functions
af8e2df9 41 * (equal?(first (cons 'pork (cons 'beef (cons 'chicken empty)))) 'pork)
42 * (equal?(rest (list 'pork 'beef 'chicken)) '(beef chicken))
43 * (equal?(first (rest ('pork beef chicken))) 'beef)
8715a946 44 * how do you get the third item?
45 * what happens when you try to get the fourth item?
46**** nested lists
af8e2df9 47 * (equal?(list 'cat (list 'duck 'bat) 'ant) '(cat (duck bat) ant))
8715a946 48 * all lists are made of cons cells
af8e2df9 49 * (equal?(first '((peas carrots tomatoes) (pork beef chicken)))
8715a946 50 (peas carrots tomatoes))
af8e2df9 51 * (equal?(rest '(peas carrots tomatoes)) '(carrots tomatoes))
52 * (equal?(rest (first '((peas carrots tomatoes) (pork beef chicken))))
8715a946 53 '(carrots tomatoes))
54 * second third ... tenth built-in
af8e2df9 55** structures
56 structures group things together, like lists. structures group a
57 fixed number of items, unlike lists.
58 example: student has name ID dorm.
59*** structure basics
60 * "(struct student (name id# dorm))"
61 this defines a structure, but doesn't actually create one.
62 * "(define freshman1 (student 'Joe 1234 'NewHall))"
63 this creates a structure
64 * fields: name, id#, dorm
65 * (equal? (student-name freshman1) 'Joe)