Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
(define l '(a)) (define p (cons l l)) (set-car! (cdr p) 'b)
在过去之后(set-car! (cdr p) 'b),p会((b) b)而不是((a) b)。为什么?
(set-car! (cdr p) 'b)
p
((b) b)
((a) b)
一个cons单元格本质上包含两个指向其他两个对象的指针。您有问题的代码将大致转换为这个伪 C:
cons
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