[plt-scheme] A question about an implementation

From: John Clements (clements at brinckerhoff.org)
Date: Thu Apr 24 15:11:14 EDT 2003

On Tuesday, April 8, 2003, at 08:53  AM, Robby Findler wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> You might consider vectors or define-struct. See Help Desk for details
> on both.
>
> Robby
>
> At Tue, 8 Apr 2003 08:55:57 +0200, "The Computer Man" wrote:
>>   For list-related administrative tasks:
>>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>> Hello, I program the play of Othello, and I would have a question in
>> connection with the structure of implementation. I thought of 
>> creating 8
>> lists, 1 lists by line in made, containing each one 8 elements and of 
>> making
>> a accessor of the cxxxxr type i.e. avoided a too great complexity.
>> I would like to know if there would be a structure more adapted @ 
>> kind of
>> situation. My goal of being modelled the boxes of the plate of play 
>> in order
>> to preserve the blows played and to analyze has each blow kel not 
>> must be
>> eaten.
>> Thank you by advance for your answers

... unless your last two sentences indicate that functional update is 
important to you.  This would be easy to build on top of vectors:

(define (vector-update vec idx new-val)
   (let ([new-vec (apply vector (vector->list vec))])
     (vector-set! new-vec idx new-val)
     new-vec))

(define (board-update board row col new-val)
   (vector-update board row (vector-update (vector-ref board row) col 
new-val)))

; test cases
; define a board:
(define test-board (vector (vector 'a 'b) (vector 'c 'd)))
; update it functionally:
(define new-board (board-update test-board 1 0 'yippee!))
; is the new one correct?
(equal? new-board (vector (vector 'a 'b) (vector 'yippee! 'd)))
; is the old one still unchanged?
(equal? test-board (vector (vector 'a 'b) (vector 'c 'd)))


john clements



Posted on the users mailing list.