Complete exercise 3.18
This commit is contained in:
parent
275fb36bd7
commit
c1988959e3
10
3_16.rkt
10
3_16.rkt
|
@ -28,6 +28,16 @@
|
||||||
1))))
|
1))))
|
||||||
(count l '()))
|
(count l '()))
|
||||||
|
|
||||||
|
(define (has-cycle? l)
|
||||||
|
(define (cycle-iter l seen-pairs)
|
||||||
|
(cond ((not (pair? l)) #f)
|
||||||
|
((memq (cdr l) seen-pairs) #t)
|
||||||
|
(else
|
||||||
|
(cycle-iter (cdr l)
|
||||||
|
(cons l seen-pairs)))))
|
||||||
|
(cycle-iter l '()))
|
||||||
|
|
||||||
|
|
||||||
;; Both give 3
|
;; Both give 3
|
||||||
(define l1 '(a b c))
|
(define l1 '(a b c))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue