================================================== Typical questions related to Quiz 2 - TDDC60, 2006 ================================================== --------------------------------------------------------------------- 1) [4 points] You will get some exercises in form of structures you need to draw graphically and graphical structures for which you need to write the corresponding Scheme-expression. Examples: see figures 2.2 and 2.3 in the course book. --------------------------------------------------------------------- 2) [3 points] Write a Scheme-procedure MAP2 with three parameters F, LIST-1 and LIST-2. With the assumption that the two lists have the same length, MAP2 computes a list whose Nth element is the result of applying F to the Nth element of LIST-1 and Nth element of LIST-2. Like so: (map2 + '(1 2 3) '(6 7 8)) => (7 9 11) (map2 cons '(1 2 3) '(6 7 8)) => ((1 . 6) (2 . 7) (3 . 8)) (map2 (lambda (x y) (+ x (* 2 y))) '(1 2 3) '(4 3 2)) => (9 8 7) You are not allowed to define in terms of MAP procedure which exists in Scheme. --------------------------------------------------------------------- 3) [6 points] The following lists contain information about students and the courses they take. The first list (students) contains information about students (person-no, name, address), the second list (courses) lists existing courses (course-code, course-name and credit-points) and the third list indicates the courses selected by students and the grades the students have obtained in the course. For example, in the latter, the sublist (800202-2253 TDDB27 4) means that the student with person-no 800202-2253 has selected the course TDDB27 and got the grade 4. (define students (list '(800202-2253 (Erik Andersson) ((Tröskareg 15) (58330 Linköping))) '(790302-4472 (Lars Hansson) ((Bygdegatan 103) (58331 Linköping))) '(820101-1927 (Anna Thurée) ((Odalgatan 202) (58331 Linköping)) '(...)))) (define courses (list '(TDDB27 Pram 4) '(TDDC60 Pram 5) '(TDDB38 Databasteknik 5) '(...))) (define selections (list '(800202-2253 TDDB27 4) '(790302-4472 TDDB38 3) '(800202-2253 TDDB38 5) '(...))) 1) For the elements of each list write the necessary CONSTRUCTOR and SELECTOR procedures. 2) Write a Scheme-procedure called WHICH-STUDENTS that takes a course code as argument and returns a list that contains the names and addresses of the students who have taken the course. Like so: > (which-students 'TDDB38) (((Erik Andersson) ((Tröskareg 15) (58330 Linköping))) ((Lars Hansson) ((Bygdegatan 103) (58331 Linköping)))) --------------------------------------------------------------------- Here are some more problems selected from the course book SICP. Exercise 2.7 (SICP) --------------------------------------------------------------------- Exercise 2.17 (SICP) --------------------------------------------------------------------- Exercise 2.33 (SICP) --------------------------------------------------------------------- Exercise 2.37 (SICP) --------------------------------------------------------------------- Exercise 2.32 (SICP) - a bit tricky ---------------------------------------------------------------------