[racket] Reading graph structure

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Aug 18 10:32:21 EDT 2011

On Aug 18, 2011, at 10:21 AM, Harry Spier wrote:

> I've done that and what displays is:
> #0=(1  . #0#)
> #0='(1 . #0#)
> 
> Again I'm not clear why this doesn't try to produce an endlessly recurring (1 . (1 . ( 1 .......  list

At this point you're entering philosophical grounds: 

 is a cyclic list (ignoring how it is constructed) a good representation for the rational, infinite list of all 1s? 

As far as my practical programming issues are concerned, I am perfectly happy with it. 

Here is a snippet from a TicTacToe implementation that uses a cyclic list: 

 ;; the class of ttt buttons
  (define ttt% 
    (shared ((turn (cons "U, Man" (cons "I, Bot" turn)))) 
    ;; The above creates the 'infinite' list ("U, Man" . ("I, Bot" . ("U, Man" . ...)))
    ;; The first person on this list is the player whose turn it is. 
    ;; You could create this list by reading the names off some input string. 
      (class button% 
        (field [status BLANK])
        ;; -> String 
        ;; what is its status? 
        (define/public (is) status)
        ;; -> Void (effect: this button is taken by the current player)
        (define/public (play)
          (define who (car turn))
          (when (and (send this is-enabled?) (string=? status BLANK))
            (set! status who)
            (send this set-label status)
            (send this enable #f)
            (when (N-in-a-row?)
              (disable-all)
              (send frame set-label (format "game's up: ~a won\n" who)))
            (set! turn (cdr turn))))
    ;; this last line uses the infinite list to switch turns 





Posted on the users mailing list.