Constructors — Creating arrays and vectors
cl_object ecl_alloc_simple_vector(
cl_elttype element_type,
cl_index length)
;
cl_object si_make_vector(
cl_object element_type,
cl_object length,
cl_object adjustablep,
cl_object fill_pointerp,
cl_object displaced_to,
cl_object displacement)
;
cl_object si_make_array(
cl_object element_type,
cl_object dimensions,
cl_object adjustablep,
cl_object fill_pointerp,
cl_object displaced_to,
cl_object displacement)
;
The function ecl_alloc_simple_vector
is the simplest constructor, creating a simple vector (i.e. non-adjustable and without a fill pointer), of the given size, preallocating the memory for the array data. The first argument, element_type
, is a C constant that represents a valid array element type (See cl_elttype).
The function si_make_vector
does the same job but allows creating an array with fill pointer, which is adjustable or displaced to another array.
element_type
is now a Common Lisp type descriptor, which is a symbol or list denoting a valid element type
dimension
is a non-negative fixnum with the vector size.
fill_pointerp
is either Cnil or a non-negative fixnum denoting the fill pointer value.
displaced_to
is either Cnil or a valid array to which the new array is displaced.
displacement
is either Cnil or a non-negative value with the array displacement.
Finally, the function si_make_array
does a similar job to si_make_function
but its second argument, dimension
, can be a list of dimensions, to create a multidimensional array.
Create one-dimensional base-string with room for 11 characters:
cl_object s = ecl_alloc_simple_vector(ecl_aet_bc, 11);
Create a one-dimensional array with a fill pointer
cl_object type = ecl_make_symbol("BYTE8","EXT"); cl_object a = si_make_vector(ecl_make_fixnum(16), type, Cnil, /* adjustable */ ecl_make_fixnum(0) /* fill-pointer */, Cnil /* displaced_to */, Cnil /* displacement */);
An alternative formulation
cl_object type = ecl_make_symbol("BYTE8","EXT"); cl_object a = si_make_array(ecl_make_fixnum(16), type, Cnil, /* adjustable */ ecl_make_fixnum(0) /* fill-pointer */, Cnil /* displaced_to */, Cnil /* displacement */);
Create a 2-by-3 two-dimensional array, specialized for an integer type:
cl_object dims = cl_list(2, ecl_make_fixnum(2), ecl_make_fixnum(3)); cl_object type = ecl_make_symbol("BYTE8","EXT"); cl_object a = si_make_array(dims, type, Cnil, /* adjustable */ Cnil /* fill-pointer */, Cnil /* displaced_to */, Cnil /* displacement */);