* irrational numbers
** strings
* "tutti frutti"
- * (= (string-append "tutti" "frutti") "tuttifrutti")
- * (= (string-append "tutti" " " "frutti") "tutti frutti")
+ * (equal? (string-append "tutti" "frutti") "tuttifrutti")
+ * (equal?(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)))
+ * (equal?(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)
+ * (equal?(cons 1 2) '(1 . 2))
+ * (define cell (cons 'a 'b)) (equal?(car cell) 'a) (equal?(cdr cell) 'b)
*** lists and list functions
- * (= '() empty (list))
+ * (equal?'() empty (list))
**** cons function
- * (= (cons 'chicken empty) '(chicken))
+ * (equal?(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 '())))
+ * (equal?(cons 'pork '(beef chicken)) '(pork beef chicken))
+ * (equal?(cons 'beef (cons 'chicken '())) '(beef chicken))
+ * (equal?(cons 'pork (cons 'beef (cons 'chicken '())))
'(pork beef chicken))
**** list function
- * (= (list 'pork 'beef 'chicken) '(pork beef chicken))
+ * (equal?(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)
+ * (equal?(first (cons 'pork (cons 'beef (cons 'chicken empty)))) 'pork)
+ * (equal?(rest (list 'pork 'beef 'chicken)) '(beef chicken))
+ * (equal?(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))
+ * (equal?(list 'cat (list 'duck 'bat) 'ant) '(cat (duck bat) ant))
* all lists are made of cons cells
- * (= (first '((peas carrots tomatoes) (pork beef chicken)))
+ * (equal?(first '((peas carrots tomatoes) (pork beef chicken)))
(peas carrots tomatoes))
- * (= (rest '(peas carrots tomatoes)) '(carrots tomatoes))
- * (= (rest (first '((peas carrots tomatoes) (pork beef chicken))))
+ * (equal?(rest '(peas carrots tomatoes)) '(carrots tomatoes))
+ * (equal?(rest (first '((peas carrots tomatoes) (pork beef chicken))))
'(carrots tomatoes))
* second third ... tenth built-in
+** structures
+ structures group things together, like lists. structures group a
+ fixed number of items, unlike lists.
+ example: student has name ID dorm.
+*** structure basics
+ * "(struct student (name id# dorm))"
+ this defines a structure, but doesn't actually create one.
+ * "(define freshman1 (student 'Joe 1234 'NewHall))"
+ this creates a structure
+ * fields: name, id#, dorm
+ * (equal? (student-name freshman1) 'Joe)