From: Jason
Subject: "Fun" with mulitdimensional arrays...
Date: 
Message-ID: <1141625934.385658.275440@j33g2000cwa.googlegroups.com>
Ok, so I'm learning about arrays now. I want to create a 5x5 array, and
I want each cell to contain a unique value. My exercise is to "rotate"
this array 90 degrees clockwise.

I'm setting up my variables, when I notice an iteresting (ie, bizarre
and annoying) thing.

Here's the code:

;; *arr-1* and *arr-2* are (in my naive opinion) both methods for
declaring a 5x5 array.

;; "Dynamic" method - I'll need to populate with data later
(setf *arr-1* (make-array '(5 5) :initial-element 0))

;; "Static" method - the data is already in place
(setf *arr-2* #5((a b c d e)
		 (f g h i j)
		 (k l m n o)
		 (p q r s t)
		 (u v w x y)))

So far so good. Now, when I print out these arrays I get:

8. Break [13]> *arr-1*
#2A((0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0))
8. Break [13]> *arr-2*
#((A B C D E) (F G H I J) (K L M N O) (P Q R S T) (U V W X Y))

Except for the "2A" (which is obviously *very* significant), these two
arrays look functionally equivalent. However, when I try to aref (3 3)
from both I get very different responses:

8. Break [13]> (aref *arr-1* 3 3)
0
8. Break [13]> (aref *arr-2* 3 3)

*** - AREF: got 2 subscripts, but #((A B C D E) (F G H I J) (K L M N O)
(P Q R S T) (U V W X Y)) has rank 1


The array created using make-array is functioning perfectly. The one I
manually created turns out to not be a multidimensional array. Rather,
it's an array five elements wide, each element of which is a list of
five items! Argh!

So, how can I declare an array 5x5 and populate it with default data
all in one shot? Is there a way?

-Jason

From: Barry Margolin
Subject: Re: "Fun" with mulitdimensional arrays...
Date: 
Message-ID: <barmar-FD19E7.01314006032006@comcast.dca.giganews.com>
In article <························@j33g2000cwa.googlegroups.com>,
 "Jason" <·······@gmail.com> wrote:

> Ok, so I'm learning about arrays now. I want to create a 5x5 array, and
> I want each cell to contain a unique value. My exercise is to "rotate"
> this array 90 degrees clockwise.
> 
> I'm setting up my variables, when I notice an iteresting (ie, bizarre
> and annoying) thing.
> 
> Here's the code:
> 
> ;; *arr-1* and *arr-2* are (in my naive opinion) both methods for
> declaring a 5x5 array.
> 
> ;; "Dynamic" method - I'll need to populate with data later
> (setf *arr-1* (make-array '(5 5) :initial-element 0))
> 
> ;; "Static" method - the data is already in place
> (setf *arr-2* #5((a b c d e)
> 		 (f g h i j)
> 		 (k l m n o)
> 		 (p q r s t)
> 		 (u v w x y)))
> 
> So far so good. Now, when I print out these arrays I get:
> 
> 8. Break [13]> *arr-1*
> #2A((0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0))
> 8. Break [13]> *arr-2*
> #((A B C D E) (F G H I J) (K L M N O) (P Q R S T) (U V W X Y))
> 
> Except for the "2A" (which is obviously *very* significant), these two
> arrays look functionally equivalent. However, when I try to aref (3 3)
> from both I get very different responses:
> 
> 8. Break [13]> (aref *arr-1* 3 3)
> 0
> 8. Break [13]> (aref *arr-2* 3 3)
> 
> *** - AREF: got 2 subscripts, but #((A B C D E) (F G H I J) (K L M N O)
> (P Q R S T) (U V W X Y)) has rank 1
> 
> 
> The array created using make-array is functioning perfectly. The one I
> manually created turns out to not be a multidimensional array. Rather,
> it's an array five elements wide, each element of which is a list of
> five items! Argh!
> 
> So, how can I declare an array 5x5 and populate it with default data
> all in one shot? Is there a way?

As you said, the #2A is significant.  The numeric prefix in #A indicates 
the rank of the array, which defaults to 1.  If you want a 2-dimensional 
array, use

#2A((a b c d e) (f g h i j) ...)

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Sacha
Subject: Re: "Fun" with mulitdimensional arrays...
Date: 
Message-ID: <YDQOf.297649$4L1.9279575@phobos.telenet-ops.be>
> (setf *arr-2* #5((a b c d e)
> (f g h i j)
> (k l m n o)
> (p q r s t)
> (u v w x y)))
>
> So far so good. Now, when I print out these arrays I get:
>
> 8. Break [13]> *arr-1*
> #2A((0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0))
> 8. Break [13]> *arr-2*
> #((A B C D E) (F G H I J) (K L M N O) (P Q R S T) (U V W X Y))

this worked for me :

CL-USER 103 > (setf *arr-2* #2A((a b c d e)
(f g h i j)
(k l m n o)
(p q r s t)
(u v w x y)))
#2A((A B C D E) (F G H I J) (K L M N O) (P Q R S T) (U V W X Y))

CL-USER 104 > (aref *arr-2* 3 3)
S


I beleive you were making a one dimentional array containing 5 lists.

Sacha
From: Jason
Subject: Re: "Fun" with mulitdimensional arrays...
Date: 
Message-ID: <1141626935.017302.290060@e56g2000cwe.googlegroups.com>
Sacha wrote:
> > (setf *arr-2* #5((a b c d e)
> > (f g h i j)
> > (k l m n o)
> > (p q r s t)
> > (u v w x y)))

This is what I was doing...

>
> CL-USER 103 > (setf *arr-2* #2A((a b c d e)
> (f g h i j)
> (k l m n o)
> (p q r s t)
> (u v w x y)))
> #2A((A B C D E) (F G H I J) (K L M N O) (P Q R S T) (U V W X Y))

... and this is what I *should* have been doing!

I see now, that I was counting the /number of rows and columns/ when I
*should have* simply counted the /number of dimensions!/

lol. I can tell the C++ style of char x[][] = new char[5][5] had me
focusing of the five, when I should have been focusing on the brackets.


Thanks!

-Jason