[plt-scheme] iteration across cyclic graph

From: Stephen De Gabrielle (spdegabrielle at gmail.com)
Date: Tue Nov 11 03:45:30 EST 2008

Hi,

I recently tried to work out how to cycle through a cycle (made with
the scheme/shared facilities);

(define colours (shared ([a (cons 'red b)]
         [b (cons 'blue c)]
         [c (cons 'green d)]
         [d (cons 'yellow e)]
         [e (cons 'orange a)])
  a))

(define current-colours colours)
(define (get-colour)
  (set! current-colours (cdr current-colours))
  (car current-colours))

This does the job, but I'm not happy with either the expression and function.

Is there a better way?

Cheers,

Stephen


Posted on the users mailing list.