CS61A_fa98_mt2_sol

CS61A_fa98_mt2_sol - CS 61A Fall 1998 Midterm 2 solutions 1...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 61A Fall 1998 Midterm 2 solutions 1. > (append (list 'a 'b) '(c d)) (A B C D) --->XX----->XX----->XX----->X/ | | | | V V V V A B C D Most people got this. The most common problem was to put quotation marks in the answer, in the printed result and/or in the diagram. The quotation marks are part of Scheme expressions, but not part of the value of those expressions! In other words, the value of the expression 'A is just A, not 'A. > (cons (list 'a 'b) (cons 'c 'd)) ((A B) C . D) --->XX------------->XX--->D | | V V XX----->X/ C | | V V A B The pair at the top, to which the initial arrow points, is the one created by the CONS. This was the part most commonly answered incorrectly. The least bad wrong answer was ((A B) . (C . D)). This is close to correct, in that if you quoted it to Scheme, you'd get this data structure. But Scheme never prints a dot followed by an open parenthesis! It uses list notation instead. (In this case it's an "improper list" because it doesn't end with an empty list in the last cdr.) Other wrong answers were ((A B) C D), which would be a proper list with an extra pair, as if the problem had been (cons (list 'a 'b) (LIST 'c 'd)) and (A B C . D), a structure of only three pairs, as if the problem had been (APPEND (list 'a 'b) (cons 'c 'd)) > (list (list 'a 'b) (append '(c) '(d))) ((A B) (C D)) --->XX------------->X/ | | V V XX----->X/ XX----->X/ | | | | V V V V A B C D The two pairs in the top row are the ones generated by LIST. It
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
always creates a list whose length is the number of arguments, which is two in this example. The first element is (A B); the second is (C D). > (cdar '((1 2) (3 4))) (2) --->X/ | V 2 (car '((1 2) (3 4))) --> (1 2) (cdr '(1 2)) --> (2) Scoring: 1/2 point per printed form, 1/2 point per box and pointer diagram, rounded down to the nearest point. Exception: Side-issue mistakes made consistently in all problems, such as putting quotation marks in the result, lost no more than 1 point altogether in the printed form and 1 point altogether in the diagram. Note: When drawing box and pointer diagrams, please be careful about the arrows; it makes your diagrams much easier to read. There should be an arrowhead at the end (next to the thing the arrow points at). The tail of the arrow should be INSIDE a box; the head should be NEXT TO a box or other datum. For example: +-----+-----+ | | /| ----->| | | / | | | |/ | +--|--+-----+ | V 2 Note how the arrow that points to the 2 starts inside the car of the pair. 2.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/23/2010 for the course CS 61A taught by Professor Harvey during the Fall '08 term at Berkeley.

Page1 / 6

CS61A_fa98_mt2_sol - CS 61A Fall 1998 Midterm 2 solutions 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online