2
(define l '(a))
(define p (cons l l))
(set-car! (cdr p) 'b)

在过去之后(set-car! (cdr p) 'b)p((b) b)而不是((a) b)。为什么?

4

1 回答 1

4

一个cons单元格本质上包含两个指向其他两个对象的指针。您有问题的代码将大致转换为这个伪 C:

struct cons {
    void *car;
    void *cdr;
};

cons *l = &cons{"a", NULL};
cons *p = &cons{l, l};  // no copy takes place, we're handling pointers here
p->cdr->car = "b";  // this changes the "l" object, and nothing else
于 2014-03-01T18:24:26.410 回答