start notes on conditions
[ozzloy@gmail.com/realm-of-racket-journey] / notes.org
index 10afb31cbf6a3135d171cb5aa31d90debfd40413..62c078860fc87d9ca66f8d110da703aa42e3b9ad 100644 (file)
--- a/notes.org
+++ b/notes.org
       this creates a structure
     * fields: name, id#, dorm
     * (equal? (student-name freshman1) 'Joe)
+*** nesting structures
+    * (struct student-body (freshmen sophomores juniors seniors))
+    * (define all-student (list a b) (list) (list c d) (list e))
+    * a b c d e can all be student struct instances
+    * nested selectors:
+      * (student-name (first (student-body-freshmen all-students)))
+*** structure transparency
+    * default is opaque
+    * opaque means comparison is by identity not value
+    * (equal? false (equal? (student 'joe 1 'dorm) (student 'joe 1 'dorm)))
+    * (equal? true (equal? freshman1 freshman1))
+    * transparent structs are compared on value
+    * create transparent struct type: (struct a (b) #:transparent)
+    * (equal? true (equal? (a 'b) (a 'b)))
+    * (define b (a b))
+    * (equal? true (equal? b b))
+    * all structures in book are transparent
+**** checkpoint
+     * basic data: booleans, symbols, numbers, strings
+     * lists
+     * structs
+     * nesting of lists and structs
+** conditions and decisions
+*** how to ask
+    * predicates are questions
+    * #t true, and #f false
+    * predicate is a function that returns true or false
+    * zero? symbol=? symbol? student?
+    * doing something like (zero? "asdf") will give an error, not false
+    * real? number? string? list? cons? empty? rational? exact-integer?
+    * equal? compares everything. still gives error if you give wrong arity
+    * the predicate indicates what kind of arguments it works on
+*** the conditionals: if and beyond
+    * (equal? 'yup (if (= (+ 1 2) 3) 'yup 'nope))
+    * invented in 1960s by john mccarthy
+    * #f is false and everything else is true, including '()
+    * examples
+      * (if '(1) 'consequent 'alternative) 'consequent
+      * (if '() 'consequent 'alternative) 'consequent
+      * (if #f 'consequent 'alternative) 'alternative
+    * ((if 'a
+           (display "consequent")
+           (display "alternative"))) ;; prints "consequent"