= SICP exercise 3.19
:categories: lisp programming-languages

[source,scheme]
----
(define (cycle? l)
  (define (rec l x)
    (cond
      ((null? x) false)
      ((eq? l x) true)
      (true (rec l (cdr x)))))
  (rec l (cdr l)))
----

Sample interactive session:

[source,scheme]
----
scheme@(guile-user)> (define true #t)
scheme@(guile-user)> (define false #f)
scheme@(guile-user)>
(define (cycle? l)
  (define (rec l x)
    (cond
      ((null? x) false)
      ((eq? l x) true)
      (true (rec l (cdr x)))))
  (rec l (cdr l)))
scheme@(guile-user)> (cycle? '(1 2 3))
$9 = #f
scheme@(guile-user)> (cycle? (make-cycle '(1 2 3)))
$10 = #t
----
