From: LoYwEnG
Subject: What is a simple array?
Date: 
Message-ID: <aa6c872e-00f7-4ef0-9f73-3cfa37a5d7e5@g22g2000pra.googlegroups.com>
"A simple array is one that is neither adjustable, nor displaced, nor
has a fill-pointer. Arrays
are simple by default."
1. This is a sentence that I can't understand from the book ANSI
Common Lisp. Could you explain its meanings.
2. Why is a one-dimensional array called vector?

From: gugamilare
Subject: Re: What is a simple array?
Date: 
Message-ID: <86f310ac-9be6-4e10-bf85-5e6449126235@h23g2000vbc.googlegroups.com>
On 21 maio, 11:32, LoYwEnG <·······@gmail.com> wrote:
> "A simple array is one that is neither adjustable, nor displaced, nor
> has a fill-pointer. Arrays
> are simple by default."
> 1. This is a sentence that I can't understand from the book ANSI
> Common Lisp. Could you explain its meanings.

An array can have a fill-pointer you want to easily add / remove
elements from its end:

(make-array 20 :fill-pointer 10)

The array created above will have total size 20, but only the first 10
entrances are considered "valid". You can add elements to the tail of
this array with VECTOR-PUSH and remove with VECTOR-POP (they are
analogous to push and pop, but they push and pop elements in the tail,
not the head). The inconvenience is that this array will always have
total size equal to 20. If you push too many elements into it, you
will get an error.

To be able to push as many elements as you want, you can create an
adjustable array by calling

(make-array 20 :adjustable t)

An array created this way can be adjusted (i.e. it's size can be
changed with ADJUST-ARRAY or with VECTOR-PUSH-EXTEND). This array by
default have a fill-pointer at position 20. Of course, you can specify
a different one if you want:

(make-array 20 :adjustable t :fill-pointer 10)

And, for the last, displaced array are "sub-arrays" of another array.
For instance:

(1) (make-array 10 :displaced-to some-existent-array :displaced-index-
offset 5)

is more or less the in-place version of

(2) (subseq some-existent-array 5 (+ 5 10))

The difference between 1 and 2 is that, if you modify the array 1, the
SOME-EXISTENT-ARRAY will also be modified in the corresponding place.
Like this:

CL-USER> (make-array 20 :initial-element 0)
#(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
CL-USER> (make-array 10 :displaced-to * :displaced-index-offset 10)
#(0 0 0 0 0 0 0 0 0 0)
CL-USER> (setf (aref * 5) 10)
10
CL-USER> ***
#(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0)

> 2. Why is a one-dimensional array called vector?

Just a "useless" convention. Vectors are much more used than multi-
dimensional arrays, so it is convenient to have a smaller name for
them.
From: ·····@franz.com
Subject: Re: What is a simple array?
Date: 
Message-ID: <6e6382bc-766a-4a76-997c-5124a11da116@w31g2000prd.googlegroups.com>
On May 21, 7:32 am, LoYwEnG <·······@gmail.com> wrote:
> "A simple array is one that is neither adjustable, nor displaced, nor
> has a fill-pointer. Arrays
> are simple by default."
> 1. This is a sentence that I can't understand from the book ANSI
> Common Lisp. Could you explain its meanings.

This simply means that if you call make-array with only its required
argument, you will always get a simple-array.  The defaults for all of
the keywords are set in such a way as to guarantee you a simple-array,
though the contrapositive is not true; i.e. if you do specify some of
the keywords that might make the array non-simple, it is an error to
assume that the array would indeed be non-simple.

> 2. Why is a one-dimensional array called vector?

Already answered by others.

Duane
From: gugamilare
Subject: Re: What is a simple array?
Date: 
Message-ID: <12338474-66db-41d3-9613-3b693e5343c9@b1g2000vbc.googlegroups.com>
On 21 maio, 13:37, ·····@franz.com wrote:
> though the contrapositive is not true;

OMG! Call all the mathematicians in the world! You found a paradox! :)

Actually, not exactly the contrapositive which is not true. Your
affirmation was that

supply no keywords => get simple array

The contrapositive is

got non-simple array => supplied some keyword

which is evidently true. What is not true is

supply some keyword => get non-simple array

which is the reversed implication.
From: Tamas K Papp
Subject: Re: What is a simple array?
Date: 
Message-ID: <77l7tmF1hqug8U1@mid.individual.net>
On Thu, 21 May 2009 07:32:41 -0700, LoYwEnG wrote:

> "A simple array is one that is neither adjustable, nor displaced, nor
> has a fill-pointer. Arrays
> are simple by default."
> 1. This is a sentence that I can't understand from the book ANSI Common
> Lisp. Could you explain its meanings. 

http://www.lispworks.com/documentation/HyperSpec/Body/t_smp_ar.htm

Click on the terms you don't understand.

> 2. Why is a one-dimensional array called vector?

I don't really understand your question.  In general, vector is a
pretty common term for sequences that are indexed by a single
nonnegative integer, used in other languages, mathematics (which of
course extends the concept), etc.

Tamas
From: John Thingstad
Subject: Re: What is a simple array?
Date: 
Message-ID: <op.uuacs3gkut4oq5@pandora>
På Thu, 21 May 2009 16:32:41 +0200, skrev LoYwEnG <·······@gmail.com>:

> "A simple array is one that is neither adjustable, nor displaced, nor
> has a fill-pointer. Arrays
> are simple by default."
> 1. This is a sentence that I can't understand from the book ANSI
> Common Lisp. Could you explain its meanings.

Well, look at the function vector-push. To push onto a vector you need to  
start with a empty array of given size and have a pointer to the first  
element. Then as you push elements onto the array the index moves. This is  
what fill pointer is for. Then there is vector-push-extend. This works as  
push but when it reaches the end of the array the array is extended (it  
grows) to allow more elements. To do this you need set ":adjustable T" in  
make array. The adjustable array will grow in "chunks" of many elements so  
you dont have to reallocate each time you push.

As for displaced arrays they have many uses. I imagine I have a array  
#2A((1 2) (3 4) (5 6)). I would like to iterate over each element.
I could see the same array as flat by making a new array declaration like  
so: (make-array (array-total-size *) :displaced_to *)
(assuming * points to the array on the repl)
OK this new array has the SAME elements as the old one. Any changes made  
to the second arrays elements will also appear in the first.
So only the Array header is different. This is what :displaced-to is for.

Keeping tract of these elements of the array structure takes up space so  
if you don't explicitly ask for them the are not in the array header.
This would be the simple-array.

> 2. Why is a one-dimensional array called vector?

Not all one dimentional arrays are vectors.
vectors can be made with make-vector. A vector is one dimentional array of  
pointers to objects.
On the other hand in make-string the array containg character elements,  
not pointers to them.
In short if a 1 dimensional array (made with make-array) has a  
:element-type which is not t (the default) it is not a vector.

---------------------
John Thingstad
From: Madhu
Subject: Re: What is a simple array?
Date: 
Message-ID: <m3bppmcuaq.fsf@meer.net>
* "John Thingstad" <·················@pandora> :
Wrote on Thu, 21 May 2009 17:18:29 +0200:

|> 2. Why is a one-dimensional array called vector?
|
| Not all one dimentional arrays are vectors.

Incorrect. If you look it up, the CLHS will tell you: Any
one-dimensional array is a vector.

<URL:http://www.franz.com/support/documentation/8.1/ansicl/dictentr/vector0.htm>

Class Precedence List: vector, array, sequence, t 
Description: The type vector is a subtype of type array; for all types
	x, (vector x) is the same as (array x (*)).


| vectors can be made with make-vector. A vector is one dimentional
| array of pointers to objects.  

Incorrect. (vectorp (vector 1 2 3)) ; T

|On the other hand in make-string the array containg character elements,
|not pointers to them.  In short if a 1 dimensional array (made with
|make-array) has a :element-type which is not t (the default) it is not
|a vector.

Incorrect

(vectorp "foo") ; T
(vectorp (vector 1 #\a "bar")) ; T
(vectorp (make-array 3 :element-type '(unsigned-byte 8))) ;T

--
Madhu
From: John Thingstad
Subject: Re: What is a simple array?
Date: 
Message-ID: <op.uuaf59l0ut4oq5@pandora>
På Thu, 21 May 2009 18:09:01 +0200, skrev Madhu <·······@meer.net>:

>
> * "John Thingstad" <·················@pandora> :
> Wrote on Thu, 21 May 2009 17:18:29 +0200:
>
> |> 2. Why is a one-dimensional array called vector?
> |
> | Not all one dimentional arrays are vectors.
>
> Incorrect. If you look it up, the CLHS will tell you: Any
> one-dimensional array is a vector.
>
> <URL:http://www.franz.com/support/documentation/8.1/ansicl/dictentr/vector0.htm>
>
> Class Precedence List: vector, array, sequence, t
> Description: The type vector is a subtype of type array; for all types
> 	x, (vector x) is the same as (array x (*)).
>
>
> | vectors can be made with make-vector. A vector is one dimentional
> | array of pointers to objects.
>
> Incorrect. (vectorp (vector 1 2 3)) ; T
>
> |On the other hand in make-string the array containg character elements,
> |not pointers to them.  In short if a 1 dimensional array (made with
> |make-array) has a :element-type which is not t (the default) it is not
> |a vector.
>
> Incorrect
>
> (vectorp "foo") ; T
> (vectorp (vector 1 #\a "bar")) ; T
> (vectorp (make-array 3 :element-type '(unsigned-byte 8))) ;T
>
> --
> Madhu

From:
http://www.lispworks.com/documentation/HyperSpec/Body/f_vector.htm

vector is analogous to list.

  (vector a1 a2 ... an)
   ==  (make-array (list n) :element-type t
                           :initial-contents
                             (list a1 a2 ... an))

I guess that's what confused me. If you create a vector with vector then  
what I said is true.


---------------------
John Thingstad
From: John Thingstad
Subject: Re: What is a simple array?
Date: 
Message-ID: <op.uuagj5bfut4oq5@pandora>
På Thu, 21 May 2009 18:09:01 +0200, skrev Madhu <·······@meer.net>:

>
> * "John Thingstad" <·················@pandora> :
> Wrote on Thu, 21 May 2009 17:18:29 +0200:
>
> |> 2. Why is a one-dimensional array called vector?
> |
> | Not all one dimentional arrays are vectors.
>
> Incorrect. If you look it up, the CLHS will tell you: Any
> one-dimensional array is a vector.
>
> <URL:http://www.franz.com/support/documentation/8.1/ansicl/dictentr/vector0.htm>
>
> Class Precedence List: vector, array, sequence, t
> Description: The type vector is a subtype of type array; for all types
> 	x, (vector x) is the same as (array x (*)).
>
>
> | vectors can be made with make-vector. A vector is one dimentional
> | array of pointers to objects.
>
> Incorrect. (vectorp (vector 1 2 3)) ; T
>
> |On the other hand in make-string the array containg character elements,
> |not pointers to them.  In short if a 1 dimensional array (made with
> |make-array) has a :element-type which is not t (the default) it is not
> |a vector.
>
> Incorrect
>
> (vectorp "foo") ; T
> (vectorp (vector 1 #\a "bar")) ; T
> (vectorp (make-array 3 :element-type '(unsigned-byte 8))) ;T
>
> --
> Madhu

; SLIME 2009-04-21
CL-USER> (make-array 10 :element-type 'character :initial-element #\Space)
"          "
CL-USER> (vectorp *)
T
CL-USER> (type-of **)
(SIMPLE-ARRAY CHARACTER (10))
CL-USER> (vector 1 2 #\a)
#(1 2 #\a)
CL-USER> (type-of *)
(SIMPLE-VECTOR 3)
CL-USER>

Confusing..

---------------------
John Thingstad
From: Pascal J. Bourguignon
Subject: Re: What is a simple array?
Date: 
Message-ID: <87octmz0sw.fsf@galatea.local>
"John Thingstad" <·······@online.no> writes:

> ; SLIME 2009-04-21
> CL-USER> (make-array 10 :element-type 'character :initial-element #\Space)
> "          "
> CL-USER> (vectorp *)
> T
> CL-USER> (type-of **)
> (SIMPLE-ARRAY CHARACTER (10))
> CL-USER> (vector 1 2 #\a)
> #(1 2 #\a)
> CL-USER> (type-of *)
> (SIMPLE-VECTOR 3)
> CL-USER>
>
> Confusing..

Types may be confusing indeed.  But both are vectors:


S/CL-USER[32]> (type-of (make-array 3 :initial-contents '(1 2 3)))

(SIMPLE-VECTOR 3)

S/CL-USER[33]> (type-of (vector 1 2 3))

(SIMPLE-VECTOR 3)


Notice that:

S/CL-USER[35]> (subtypep '(SIMPLE-ARRAY CHARACTER (3)) '(vector * 3))

T
T

-- 
__Pascal Bourguignon__
From: LoYwEnG
Subject: Re: What is a simple array?
Date: 
Message-ID: <442cff2e-72ef-4065-88cf-fe9291d06fb0@x31g2000prc.googlegroups.com>
On May 21, 10:32 pm, LoYwEnG <·······@gmail.com> wrote:
> "A simple array is one that is neither adjustable, nor displaced, nor
> has a fill-pointer. Arrays
> are simple by default."
> 1. This is a sentence that I can't understand from the book ANSI
> Common Lisp. Could you explain its meanings.
> 2. Why is a one-dimensional array called vector?


Thank everyone!
In fact, I am not good at English and it was the first time that I
asked some questions in English.At first I was a little afraid. But
now I'm very happy. Thanks for your help!

лл£¡£º£©