#lang planet neil/sicp
(define (check-loop x)
(let ((checked-list '()))
(define (check-loop-temp x)
(cond ((null? x) false)
((checked? (car x)) true)
(else
(begin (set! checked-list (cons (car x) checked-list))
(check-loop-temp (cdr x))))))
(define (checked? x)
(define (checked-temp? x checked-list)
(cond ((null? checked-list) false)
((eq? (car checked-list) x) true)
(else (checked-temp? x (cdr checked-list)))))
(checked-temp? x checked-list))
(check-loop-temp x)))
(define z (cons 'a (cons 'b (cons 'c '()))))
(set-cdr! (cddr z) z)
(check-loop z)