Evil Cow <·······@BovinePastures.moo> writes:
> Does Common Lisp support Array Slices? And if so, how do I use
> them?
Yes.
In Common Lisp this is called a displaced array. You can create
displaced arrays with the :DISPLACED-TO keyword argument to
MAKE-ARRAY. A more in-depth discussion and a few examples can be
found under the Common Lisp HyperSpec entry for MAKE-ARRAY.
http://www.lispworks.com/reference/HyperSpec/Body/f_mk_ar.htm
Carl Shapiro <·············@panix.com> writes:
> Evil Cow <·······@BovinePastures.moo> writes:
>
> > Does Common Lisp support Array Slices? And if so, how do I use
> > them?
>
> Yes.
Weeeeel. Mostly :)
> In Common Lisp this is called a displaced array. You can create
> displaced arrays with the :DISPLACED-TO keyword argument to
> MAKE-ARRAY. A more in-depth discussion and a few examples can be
> found under the Common Lisp HyperSpec entry for MAKE-ARRAY.
>
> http://www.lispworks.com/reference/HyperSpec/Body/f_mk_ar.htm
Yes. That is all very good. However you cannot do the following with
displaced arrays.
* (defvar *aaa* (make-array '(3 3) :initial-contents '((1 2 3)
(4 5 6)
(7 8 9))))
*AAA*
* *aaa*
#2A((1 2 3) (4 5 6) (7 8 9))
Now you cannot get the sub array
#2A((2 3) (5 6))
by displacing. This is because of the requirement that arrays be
stored in row major order and that displacing works on this
assumption.
OTOH :)
* (defvar *as* (array-slices:make-array-slice '(2 2) *aaa* '(0 1)))
*AS*
* *as*
#2A((2 3) (5 6))
(type-of *)
ARRAY-SLICES:ARRAY-SLICE
Where the ARRAY-SLICES package is a little piece of code I'll make
available soon in the CLOCC.
Cheers
--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488
715 Broadway 10th Floor fax +1 - 212 - 995 4122
New York, NY 10003, USA http://bioinformatics.cat.nyu.edu
"Hello New York! We'll do what we can!"
Bill Murray in `Ghostbusters'.
Marco Antoniotti <·······@cs.nyu.edu> writes:
> Yes. That is all very good. However you cannot do the following with
> displaced arrays.
>
> * (defvar *aaa* (make-array '(3 3) :initial-contents '((1 2 3)
> (4 5 6)
> (7 8 9))))
> *AAA*
> * *aaa*
> #2A((1 2 3) (4 5 6) (7 8 9))
>
> Now you cannot get the sub array
>
> #2A((2 3) (5 6))
>
> by displacing. This is because of the requirement that arrays be
> stored in row major order and that displacing works on this
> assumption.
On the Lisp Machine, this feature is known as a conformally displaced
array. As you have discovered, it is quite easy to get conformal
displacement within the confines of ANSI Common Lisp.
Carl Shapiro <·············@panix.com> writes:
> Marco Antoniotti <·······@cs.nyu.edu> writes:
>
> > Yes. That is all very good. However you cannot do the following with
> > displaced arrays.
> >
> > * (defvar *aaa* (make-array '(3 3) :initial-contents '((1 2 3)
> > (4 5 6)
> > (7 8 9))))
> > *AAA*
> > * *aaa*
> > #2A((1 2 3) (4 5 6) (7 8 9))
> >
> > Now you cannot get the sub array
> >
> > #2A((2 3) (5 6))
> >
> > by displacing. This is because of the requirement that arrays be
> > stored in row major order and that displacing works on this
> > assumption.
>
> On the Lisp Machine, this feature is known as a conformally displaced
> array. As you have discovered, it is quite easy to get conformal
> displacement within the confines of ANSI Common Lisp.
I am not familiar with the notion of "conformal displacement". What
is it exactly?
Note that my "array-slices" are a hack. You cannot use AREF to index
in them. You either have to use a ARRAY-SLICES:REF method or you have
to ARRAY-SLICES:CONVERT-TO-ARRAY to "copy out" the slice from the
original array.
Cheers
--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488
715 Broadway 10th Floor fax +1 - 212 - 995 4122
New York, NY 10003, USA http://bioinformatics.cat.nyu.edu
"Hello New York! We'll do what we can!"
Bill Murray in `Ghostbusters'.
In article <···············@octagon.valis.nyu.edu>,
Marco Antoniotti <·······@cs.nyu.edu> wrote:
>Carl Shapiro <·············@panix.com> writes:
>> On the Lisp Machine, this feature is known as a conformally displaced
>> array. As you have discovered, it is quite easy to get conformal
>> displacement within the confines of ANSI Common Lisp.
>
>I am not familiar with the notion of "conformal displacement". What
>is it exactly?
It allows the displaced array to refer to a rectangle within the original
array, rather than a linear section of the row-major storage as standard CL
displacement does. I think it was created for the benefit of the window
system, so that the storage for a window could be displaced to the
appropriate portion of the frame buffer memory.
--
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.