Inconsistent charts with pointer and pointer in SICP

The structure and interpretation of the graphic and pointing diagrams of computer programs in Figures 3.16 and 3.17 do not look equivalent (purely with respect to value, and not to memory), although they do say so. ("When we look at it as a list, z1 and z2 both represent the" same "list, ((ab) ab)) ", p. 258)

 (define x (list 'a 'b)) (define z1 (cons xx)) (define z2 (cons (list 'a 'b) (list 'a 'b))) 

SICP draws a pair of z1 as follows:

enter image description here

and z2:

enter image description here

The arrows in the pair z1 do not seem to indicate the whole pair, x . They do not even point to the same thing, despite the fact that they got the same (memory and cost) pair. I would rate the first chart as (ab) and the second as ((ab) ab)

I could guess that each arrow actually points to the whole pair, x , but in Figure 2.3 on page 98:

enter image description here

it very clearly points to the entire box, pointing to the side or between two elements.

Do I understand the wrong pointer diagrams or something else?

+7
lisp scheme sicp
source share
2 answers

Your last guess is correct. The dot indicates where the pointer value, the entire double square that the arrow points to, is the target. It doesn’t matter if it points to the side, upper middle, upper left or upper right. This is a whole couple, which is the "address" of the object.

You cannot specify a part of an object without accessing its part with car and cdr . The second thing you do, you have everything that it was aimed at, and not an indirect pointer. (car '(ab)) ; ==> a (car '(ab)) ; ==> a and a have no list entity that still points to it until garbage is collected.

We could illustrate this as follows:

 [=#1|#3|#2] [=#2|#3|()] [=#3|a |#4] [=#4|b |()] 

The first value with = # is the location of the window itself, and the next two are car and cdr . Above x points to address C # 3 and z1 to # 1. Let z2

 [=#5|#6|#8] [=#6|a |#7] [=#7|b |()] [=#8|#9|()] [=#9|a |#10] [=#10|b |()] 

As you can see, z2 uses two more cons than z1 , since it does not reuse the same object as both elements of its list, but uses separate similar lists.

In the drawings, both car and cdr of z1 point to the same list x . z2 points to two different lists, but the items in these lists are the same.

The reason for this is that the characters are single. That way, you only have one symbol object for a and a rating of 'a in two different places will point to the same a . Other singletones #f , #t and ()

cons always creates a new pair, and list is just a procedure in which cons together arguments. Thus, the same code (list 'a 'b) two places in the expression create two different objects that look the same.

 (eq? (car z1) (cdr z1)) ; ==> #t same object (eq? (car z2) (cdr z2)) ; ==> #f not same object (equal? (car z2) (cdr z2)) ; ==> #t they look the same, but they are not the same. (created at different places) 

Quoted data can be seen as created all at once before starting the program. So it is undefined.

 (eq? '(ab) '(ab)) ; ==> #t or #f (undefined) (eq? '(bc) (cdr '(abc))) ; ==> #t or #f (undefined) 

The reason is that the scheme is allowed, but not required, to reuse data in the same way as with the z1 structure.

+5
source share

You read too much. :-) If it points to a field anywhere, suppose it is a pointer to this cons cell. You cannot specifically point to the car or cdr .

+10
source share

All Articles