Page 1 of 1

Creating array with elements of a custom type

Posted: Tue Dec 30, 2008 6:28 am
by TPJ
Had a hard day coding in CL and looking for basic knowledge on this language.

Let's assume I'll define a structure:

Code: Select all

(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

Posted: Tue Dec 30, 2008 7:10 am
by ramarren
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

Posted: Tue Jan 06, 2009 4:24 am
by dlweinreb
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.)