理系学生日記

おまえはいつまで学生気分なのか

問題3-13 (3.3.1 Mutable List Structure)

どうなるかって無限ループだよ >< 泣ける!!!!

(define (last-pair x)
  (if (null? (cdr x))
      x
      (last-pair (cdr x))))
(define (make-cycle x)
  (set-cdr! (last-pair x) x)
  x)
(define z (make-cycle (list 'a 'b 'c)))
(last-pair z)

last-pair でずっとリストが null にならないものだから..