From: daniel watson Date: Thu, 4 Aug 2016 20:04:27 +0000 (-0700) Subject: replace = with equal? where necessary X-Git-Url: http://challenge-bot.com/repos/?p=ozzloy%40gmail.com%2Frealm-of-racket-journey;a=commitdiff_plain;h=af8e2df9747feeb0559f6edba073ed2b88b78049 replace = with equal? where necessary --- diff --git a/notes.org b/notes.org index ebc40bf..10afb31 100644 --- a/notes.org +++ b/notes.org @@ -12,43 +12,54 @@ * 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)