Lecture: 10-23-2012

posted Oct 23, 2012, 6:25 AM by Samuel Konstantinovich   [ updated Nov 20, 2012, 5:42 AM ]
;10/23/2012
;Topic: List Box Diagrams, Lists with sub-lists

;The following questions are exactly the same difficulty 
;as your final exam list questions

;#########PART 1#########
(define M '( (2 3) (7 8) (4 5)))
;Make a box/arrow diagram then evaluate:
(car M);a
(cdar M);b
(cadr M);c
(caaddr M);d

;########PART 2##########
;The next part requires you to write expressions like 
;the 4 examples above.

;Write a scheme expression to:
;get 2 from the list M -> (car (car M))   OR  (caar M)  
;get 7 from the list M
;get 8 from the list M   ; Warning: Don't stop at (8) you need to get 8.
;get (4 5) from the list.

;#########PART 3###########.
;These functions require you to break a list up with
;car/cdr and reassemble it with cons/append

;Write a function that removes all of the 0's from a list.
;(stripZero '(1 10 30 0 4 0)) ->  (1 10 30 4)

;Write a function that removes the n'th element of a list. 
;(removeNth L n)    n must be from 0 to length of the list - 1
;(removeNth '(a b c) 1)  ->  (a c)  because 
;(removeNth '(a b c) 3)  ->  (a b c)  because the n is longer 
;                            than the list so there is nothing to remove

;Write a function that inserts a value into the list at position n:
;(insert L value n)
;(insert '(1 3 4) 88 0) -> (88 1  3 4)
;(insert '(1 3 4) 88 2) -> (1  3 88 4)
;(insert '(1 3 4) 7 3) -> (1 3 4 7)
;(insert '() 7 3) -> (7)  ;when the index is too large
                            ;place the element at the end of the list
Comments