问题
My question was marked as duplicate, and closed
How to deal with cycles in recursive functions in scheme?
I'm asking again:
I have this code:
(define x (list 1 2 3))
(set-cdr! (cddr x) x)
(define (list? x)
(and (pair? x) (or (null? (cdr x)) (list? (cdr x)))))
(display (list? x))
(newline)
and function list?
freezes when it find cycle (because it's infinite loop). How scheme code usually work with cycles like that? I'm not asking how to detect cycles. I'm asking: how this is done in scheme code?
来源:https://stackoverflow.com/questions/60809809/how-scheme-code-usually-deal-with-cycles-in-list-processing-recursive-functions