CS61A_sp95_mt2_sol

CS61A_sp95_mt2_sol - CS 61A Spring 1995 Midterm 2 solutions...

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

CS 61A Spring 1995 Midterm 2 solutions 1. > (cddaar '(((a b c d e) (f g h i j)) ((l m n o p) (q r s t u)))) (C D E) (car '(((a b c d e) (f g h i j)) ((l m n o p) (q r s t u)))) ===> ((a b c d e) (f g h i j)) (car '((a b c d e) (f g h i j))) ===> (a b c d e) (cdr '(a b c d e)) ===> (b c d e) (cdr '(b c d e)) ===> (c d e) The box and pointer diagram for this is just +---+---+ +---+---+ +---+---+ | | | | | | | | /| ---------> | | | ----->| | | ----->| | | / | | | | | | | | | | | |/ | +-|-+---+ +-|-+---+ +-|-+---+ | | | V V V C D E > (cons '(a b) (append '(c d) '(e f))) ((A B) C D E F) Some people said ((a b) . (c d e f)) but Scheme never prints the sequence ". (" in representing a list structure. In the picture below, the starred pair is the one created by the CONS invocation. *********** *+---+---+* +---+---+ +---+---+ +---+---+ +---+---+ *| | |* | | | | | | | | | | | /| --------->*| | | ----------->| | | ----->| | | ----->| | | ----->| | | / | *| | | |* | | | | | | | | | | | | | | |/ | *+-|-+---+* +-|-+---+ +-|-+---+ +-|-+---+ +-|-+---+ ***|******* | | | | | V V V V | | C D E F | V +---+---+ +---+---+ | | | | | /| | | | ----->| | | / | | | | | | | |/ | +-|-+---+ +-|-+---+ | |

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

View Full Document
V V A B Scoring: one-half point for each printed result, one-half point for 2. Type of last element of each result. > '(list (count 'hello)) (LIST (COUNT 'HELLO)) So the last element is the (sub)list (COUNT 'HELLO). --> LIST > '(list count) (LIST COUNT) So the last element is the word COUNT. --> NON-NUMERIC WORD > (list 'count count) (COUNT #<PROCEDURE COUNT>) So the last element is the procedure named count. --> PROCEDURE > (list 'hello (count 'hello)) (HELLO 5) So the last element is the number 5. --> NUMBER Scoring: One half point each, rounded down. 3. Tree-accumulate. Here is the solution we were expecting:
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 / 5

CS61A_sp95_mt2_sol - CS 61A Spring 1995 Midterm 2 solutions...

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

View Full Document
Ask a homework question - tutors are online