[racket] Reading graph structure

From: Harry Spier (harryspier at hotmail.com)
Date: Thu Aug 18 12:04:13 EDT 2011

Many thanks,

  This explanation and the example from Ref. manual 3.9.8 Immutable Cyclic Data makes everything clearer.

Example:> (let* ([ph (make-placeholder #f)]         [x (cons 1 ph)])    (placeholder-set! ph x)    (make-reader-graph x))#0= '(1 . #0#)

> Subject: Re: [racket] Reading graph structure
> From: matthias at ccs.neu.edu
> Date: Thu, 18 Aug 2011 10:32:21 -0400
> CC: users at racket-lang.org
> To: harryspier at hotmail.com
> 
> 
> 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 
> 
> 
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110818/88a66557/attachment.html>

Posted on the users mailing list.