Lecture: 11-05-2012

posted Nov 5, 2012, 7:16 AM by Samuel Konstantinovich   [ updated Nov 20, 2012, 5:45 AM ]
Announcements:
-Due to scheduling you have an exam on Friday. 
-If you have a trip on Friday, you DO NOT HAVE PERMISSION TO MISS THE EXAM for the trip.

Goal: Practice with lists
QUESTIONS FROM CLASS (solutions to be posted at the end of the day)
PART 1 Trace through the functions on paper:
;A
(define (goober L M)
  (cond
    ((or (null? L) (null? M)) '())
    (else (cons (+ (car L)(car M)) (goober (cdr L) (cdr M))))))
;Trace to evaluate:
(goober '(1 3 4) '(2 9))

;B
(define (bergoo Q)
  (cond
    ((null? Q) Q)
    ((> (car Q) 5) (append (bergoo (cdr Q))(list (car Q))))
    (else (cons (car Q) (bergoo (cdr Q))))))
;Trace to evaluate:
(bergoo '(1 9 3 12))

;PART 2 Practice with lists:
;Start by writing a function that works without sublists, then add the sublist case afterwards.
;C. Write a function that deletes the even numbers from a list with sublists
;D. Write a function that negates all values of a list with sublists.


Comments