This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Creating array with elements of a custom type

3 posts · 2451 views

Had a hard day coding in CL and looking for basic knowledge on this language.

Let's assume I'll define a structure:
(defstruct my-Str
  (slot-1 0 :type fixnum)
  (slot-2 0.0d0 :type double-float))
It's a new type. How can I make an array of elements of that type? I've tried (make-array (list 5) :element-type 'my-Str), but all I got was an array of type T.

Re: Creating array with elements of a custom type

The purpose of array types is to allow implementation to use specialized memory layout for the array. The specification allows the type to be upgraded to most specific such type (see http://www.lispworks.com/documentation/ ... upgr_1.htm). In the case of custom types no specialized layout is possible in general (custom type redefinition is allowed at any time), so the array is just an array of pointers, that is, of type T.

Re: Creating array with elements of a custom type

Just don't specify an element type. Then the array elements can hold any Lisp object.

(It's better not to use the word "pointer" when talking about Lisp, I've found.)