Re: Function ARRAY-ELEMENT-TYPE



In article
<96353525-4cf6-4cdf-b02a-09159e43252b@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
danb <sogwaldan@xxxxxxxxx> wrote:

* (array-element-type (MAKE-ARRAY '(2)
:ELEMENT-TYPE 'INTEGER
:INITIAL-CONTENTS '(1 2)))
=> T

Why does this function exist? It doesn't seem to do much.

Which function? array-element-type ?
It returns the type T in your example. That's fine.

Your Lisp has decided that the element type of
the above array is of type T. Means it
does not have a special array type for
arrays with element type INTEGER.

Read about Array Upgrading:
http://www.lisp.org/HyperSpec/Body/sec_15-1-2-1.html

Here is an example where a Lisp does not upgrade an
element type:

? (array-element-type (MAKE-ARRAY '(2)
:ELEMENT-TYPE 'fixnum
:INITIAL-CONTENTS '(1 2)))
FIXNUM

See also these examples:

? (array-element-type (MAKE-ARRAY '(2)
:ELEMENT-TYPE '(unsigned-byte 4)
:INITIAL-CONTENTS '(1 2)))
(UNSIGNED-BYTE 8)

? (array-element-type (MAKE-ARRAY '(2)
:ELEMENT-TYPE '(unsigned-byte 9)
:INITIAL-CONTENTS '(1 2)))
(UNSIGNED-BYTE 16)




--Dan

------------------------------------------------
Dan Bensen
http://www.prairienet.org/~dsb/

cl-match: expressive pattern matching in Lisp
http://common-lisp.net/project/cl-match/

--
http://lispm.dyndns.org/
.



Relevant Pages

  • Re: modifying array access syntax
    ... >>> possible performance drawbacks for a moment, Common Lisp appears to ... Only horrendous if you don't appreciate what function this notation ... That is, at some level, the difference between an array and a function is ...
    (comp.lang.lisp)
  • Re: should (setf aref) coerce?
    ... is not quite clear what the spec requires. ... the only purpose of declarations is to allow compiler ... AFAIK array element types have ... the element type defaults to T. ...
    (comp.lang.lisp)
  • Re: 3 questions about arrays
    ... array can already use up at least all of physical memory and quite ... And since the default in lisp is to not include type declarations, ... computer so a fast fixnum should be at most 32 bits. ... you as the programmer can always create larger bit vectors if you ...
    (comp.lang.lisp)
  • Re: Lisp collections
    ... Lisp has it. ... > index, like a normal array. ... You should use lists when lists are the natural way to represent the ... > to inherit from enumerable-collection, and foreach should be a generic ...
    (comp.lang.lisp)
  • Re: The joy of garbage collection
    ... the underlying lisp takes care of it for you. ... array and store things in it appropriate to the imaginary ... All the things you put in it don't have pointers ... > storing unboxed data in the heap ...
    (comp.lang.lisp)