Complete exercise 3.18

This commit is contained in:
Oliver Payne 2022-05-03 22:18:22 +01:00
parent 275fb36bd7
commit c1988959e3
1 changed files with 10 additions and 0 deletions

View File

@ -28,6 +28,16 @@
1))))
(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
(define l1 '(a b c))