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セルには、基本的に、他の 2 つのオブジェクトへの 2 つのポインターが含まれています。問題のコードは、大まかに次の疑似 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 に答える