lab9 - CS 61A Week 9 Solutions LAB ASSIGNMENT 3.12 append...

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

View Full Document Right Arrow Icon
CS 61A -- Week 9 Solutions LAB ASSIGNMENT: 3.12 append vs. append! exp1 is (b); exp2 is (b c d). Append (without the !) makes copies of the two pairs that are part of the list x. (You can tell because it uses cons, which is the constructor function that generates a brand new pair.) Append! does not invoke cons; it mutates the existing pairs to combine the two argument lists. 2. Set! vs. set-cdr! There are two ways to think about this, and you should understand both of them: The syntactic explanation -- SET! is a special form; its first argument must be a symbol, not a compound expression. So anything of the form (set! (. ..) . ..) must be an error. The semantic explanation -- SET! and SET-CDR! are about two completely different purposes. SET! is about the bindings of variables in an environment. SET-CDR! is about pointers within pairs. SET! has nothing to do with pairs; SET-CDR! has nothing to do with variables. There is no situation in which they are interchangeable. (Note:
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

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

Page1 / 2

lab9 - CS 61A Week 9 Solutions LAB ASSIGNMENT 3.12 append...

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

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