缺少的部分是(b)和(b c d)
#lang R5RS
(define (append x y)
(if (null? x)
y
(cons (car x) (append (cdr x) y))))
(define (append! x y)
(set-cdr! (last-pair x) y)
x)
(define (last-pair x)
(if (null? (cdr x))
x
(last-pair (cdr x))))
(define x (list 'a 'b))
(define y (list 'c 'd))
(define z (append x y))
(display z)
(newline)
(display (cdr x))
(newline)
(define w (append! x y))
(display w)
(newline)
(display (cdr x))
运行结果
(a b c d)
(b)
(a b c d)
(b c d)
附上两种方式的盒子指针
第一种
第二种