From: Russell G. Almond
Subject: [Common Lisp] Are arrays stored in row-major form?
Date: 
Message-ID: <ALMOND.92Jun2184651@bass.statsci.com>
CLtL-2 seems to danse around this issue, but in Common Lisp are arrays
guarenteed to be stored in row major form, or is this just
one way to implement functions like row-major-aref and the like.

In particular, I have the following bit of code:


;;; Three dimensional array
(setq *a1* #3A(((0 1) (2 3)) ((0 1) (2 3)) ((0 1) (2 3))))

;;; each two dimensional sub-array as a vector.
(setq *a1a* (make-array '4 :displaced-to *a1*
			:displaced-index-offset 0))
(setq *a1b* (make-array '4 :displaced-to *a1*
			:displaced-index-offset 4))
(setq *a1c* (make-array '4 :displaced-to *a1*
			:displaced-index-offset 8))

;;; multiply the second two sub arrays by a constant.
(map-into *a1c* #'(lambda (x) (* 3 x)) *a1c*)
(map-into *a1b* #'(lambda (x) (* 2 x)) *a1b*)

(print *a1*)

Should this produce 

   #3A(((0 1) (2 3)) ((0 2) (4 6)) ((0 3) (6 9)))

In all implementations?

I've tested it on Allegro-v4.1 and CMU CL 15e and it seems to work
(you may need to define map-into for some implementations).

Thanks in advance.


			Russell Almond			   
Statistical Sciences, Inc.		U. Washington
1700 Westlake Ave., N Suite 500		Statistics, GN-22
Seattle, WA  98109			Seattle, WA  98195
(206) 283-8802				
······@statsci.com			······@stat.washington.edu
From: Barry Margolin
Subject: Re: [Common Lisp] Are arrays stored in row-major form?
Date: 
Message-ID: <10j89eINNf93@early-bird.think.com>
In article <···················@bass.statsci.com> ······@statsci.com (Russell G. Almond) writes:
>CLtL-2 seems to danse around this issue, but in Common Lisp are arrays
>guarenteed to be stored in row major form, or is this just
>one way to implement functions like row-major-aref and the like.

P.445, paragraph 3 says, "The mapping [of displaced arrays] treats both
arrays as if they were one-dimensional by taking the elements in row-major
order ...."  And p.446 says, "arrays are, in effect, stored in row-major
order for purposes of sharing."

While this doesn't strictly require that arrays actually be *stored* in
row-major order, I can't imagine any implementation doing otherwise.  In
fact, ZetaLisp originally had column-major arrays, and it was changed
incompatibly when Common Lisp was put on the Lisp Machines.
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar