[racket] do loops in racket, also srfi/25 query

From: Joe Gilray (jgilray at gmail.com)
Date: Sun Mar 25 01:01:30 EDT 2012

I was playing around with ProjectEuler #11 and found a lisp solution and
adapted it to Racket.  Part of the solution had code like the following to
find products of values in a 20x20 vector.

(define (prod-of-vec-lines-of-length-4 v ix iy dx dy)
  (do ([p 1 (* p (if (in-vector? x y 20 20) (vector-ref v (+ (* 20 y) x))
       [x ix (+ x dx)]
       [y iy (+ y dy)]
       [c 0 (add1 c)])
    ((= c 4) p)))

I realize I've hard-coded this in a very ugly fashion to 20x20 vectors.

My questions are:

1) Is there a more Racket-idiomatic way to write the "do" loop above?
2) If I wanted to use srfi/25 to do this in a nicer fashion, how would I
read in the array? - I liked being able to read in the vector with simply
(read in) - is there a simply , one-line way to convert a vector to an
array (make-array (shape 0 20 0 20) vec) puts the entire 400 element vector
into the first element of the array!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120324/c3bcd5e8/attachment.html>

Posted on the users mailing list.