[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

What does "same type" mean for arrays?

Chris Riesbeck

6/11/2015 8:35:00 PM

The Hyperspec entry for ADJUST-ARRAY says "The result is an array of the
same type and rank as array..."

http://clhs.lisp.se/Body/f_...

So I was surprised that ADJUST-ARRAY of a SIMPLE-ARRAY returns an
adjustable (non-simple) ARRAY in Allegro CL, e.g.,

(let ((x #(1 2 3))) (list (type-of x) (type-of (adjust-array x 5))))

returns ((SIMPLE-ARRAY T (3)) (ARRAY T (5))). SBCL and Lispworks on the
other hand return SIMPLE-VECTOR for the value of X and ADJUST-ARRAY.

But it was pointed out to me that the entry for SUBSEQ also uses the
phrase "same type" in the following context:

"The result subsequence is always of the same type as sequence. If
sequence is a vector, the result is a fresh simple array of rank one
that has the same actual array element type as sequence."

http://clhs.lisp.se/Body/f_subseq....

I.e., the first sentence says "same type," but the second sentence says
that something like

(let ((x (make-array 3 :adjustable t))) (list (type-of x) (type-of
(subseq x 1))))

must return SIMPLE-ARRAY for the SUBSEQ, and indeed Allegro, Lispworks,
and SBCL all return ((ARRAY T (3)) (SIMPLE-ARRAY T (2))) .

So does "same type" mean "same element type" for arrays, and it's
undefined whether ADJUST-ARRAY returns a simple array given a simple
array? Is this clarified in the standard anywhere?



1 Answer

Pascal J. Bourguignon

6/11/2015 9:07:00 PM

0

Chris Riesbeck <Chris.Riesbeck@gmail.com> writes:

> So does "same type" mean "same element type" for arrays, and it's

Yes.

> undefined whether ADJUST-ARRAY returns a simple array given a simple
> array? Is this clarified in the standard anywhere?

If the array is adjustable, then ADJUST-ARRAY must adjust it and return it
but otherwise it _may_ return a simple array. This is because when
creating an array that is not expressely adjustable, the implementation
may still make it actually adjustable: an implementation can be
simplified by making all the arrays adjustable.


clhs adjust-array:

If adjust-array is applied to an array that is actually adjustable,
the array returned is identical to array. If the array returned by
adjust-array is distinct from array, then the argument array is
unchanged.

clhs make-array:

If adjustable is non-nil, the array is expressly adjustable (and so
actually adjustable); otherwise, the array is not expressly
adjustable (and it is implementation-dependent whether the array is
actually adjustable).



$ clall -r '(adjustable-array-p (adjust-array (make-array 2) 3))'

Armed Bear Common Lisp --> NIL
Clozure Common Lisp --> NIL
CLISP --> NIL
CMU Common Lisp --> NIL
ECL --> T
SBCL --> NIL

However, ECL still has actually non-adjustable arrays:

$ clall -r '(adjustable-array-p (make-array 2))'

Armed Bear Common Lisp --> NIL
Clozure Common Lisp --> NIL
CLISP --> NIL
CMU Common Lisp --> NIL
ECL --> NIL
SBCL --> NIL


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk