Emboldened by the two helpful replies I received for the
previous Lisp question... (btw, thanks Arthur Lemmens &
& Rainer Joswig :-)
Does CL have array slices, in the sense that F90 does?
Suppose I have an array I made with:
(setf a (make-array '(4 4) :initial-contents
'((1 1 1 1)
(2 2 2 2)
(3 3 3 3)
(4 4 4 4))))
and now I'd like to extract a new array out, namely,
the third row ... #1A(3 3 3 3) ... as an array.
In F90 I would just do something like:
INTEGER, DIMENSION(4,4) :: A = &
(/ 1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4 /)
...
! print the third row of A.
PRINT *, A(3,:)
Is this what displaced arrays are used for? When I read about
them in the CLHyperSpec, displaced arrays looked a lot like
an ancient Fortran EQUIVALENCE ... (ugh!)
-lg
--
Louis Glassy (······@cs.montana.edu)
Department of Computer Science
Montana State University
Bozeman, Montana 59717 USA
In article <············@netra.msu.montana.edu>, Louis Glassy
<······@acheta.nervana.montana.edu> wrote:
> Is this what displaced arrays are used for? When I read about
> them in the CLHyperSpec, displaced arrays looked a lot like
> an ancient Fortran EQUIVALENCE ... (ugh!)
The original array and the displaced array are sharing the
elements. Changing entries in the displaced array will also
change the original array entry.
--
http://www.lavielle.com/~joswig
In article <············@netra.msu.montana.edu>,
Louis Glassy <······@acheta.nervana.montana.edu> wrote:
>In F90 I would just do something like:
...
> PRINT *, A(3,:)
>
>Is this what displaced arrays are used for? When I read about
>them in the CLHyperSpec, displaced arrays looked a lot like
>an ancient Fortran EQUIVALENCE ... (ugh!)
Yes, that's essentially what displaced arrays are. Since you can specify
an offset, they can be used as a way to get a slice:
(print (make-array (array-dimension a 1)
:displaced-to a
:displaced-index-offset (* 3 (array-dimension a 1))))
You could easily define a function ARRAY-SLICE to generalize this.
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.