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

From: Pierpaolo Bernardi (olopierpa at gmail.com)
Date: Wed Mar 28 04:36:06 EDT 2012

On Tue, Mar 27, 2012 at 18:55, Joe Gilray <jgilray at gmail.com> wrote:
> Thanks (again) Rodolfo,
>
> Do people use the srfi/25 arrays much?  Or is the normal practice to simply
> use vector with a little "reference arithmetic"?

The most normal practice, I think, is to use nested vectors, maybe
with a few ad-hoc help functions.

There's nothing wrong with srfi/25 arrays, however, (except for the
broken format of shape parameters). I use them sometimes.
Maybe one array library should be promoted to be an official part of Racket?

FWIW, my solution of Euler #11 starts with:

(define grid
  '#(#(08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08)
     #(49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00)
     ...
     ))


> On Mon, Mar 26, 2012 at 9:26 PM, Rodolfo Carvalho <rhcarvalho at gmail.com>
> wrote:
>>>
>>> Yes, I could read the data into a list and then create an array from it:
>>>
>>> (array-ref (apply array (shape 0 3 0 3) '(1 2 3 4 5 6 7 8 9)) 2 2)
>>> 9
>>>
>>> But, I don't seem to be able to do the same from a vector:
>>>
>>> (array-ref (apply array (shape 0 3 0 3) #(1 2 3 4 5 6 7 8 9)) 2 1)
>>> apply: expects type <proper list> as 3rd argument, given: '#(1 2 3 4 5 6
>>> 7 8 9); other arguments were: #<procedure:array>
>>> #<array:srfi-9-record-type-descriptor>
>>
>> It's late night here and I didn't look at the docs, but from the error
>> message it seems that you cannot pass a vector to the array constructor.

To be precise: we cannot use a vector as the last argument to apply.

Cheers
P.


Posted on the users mailing list.