Search code examples
global-variableslispcommon-lispread-eval-print-loop

Usage of defparameter


I wonder if it is because i do no understand something about the core of the defparameter macro.

So, this gives a weird mistake. I start with:

(defparameter *x* #(1 4 7))
(defparameter *y* #(2 3 55))

Everything's fine but then this:

(defparameter *res* (make-array * :adjustable t :fill-pointer 0))

gives a mistake, which I do not get at all:

 The value                                                                       
 *Y*                                                                           
 is not of type                                                                  
 (OR (MOD 4611686018427387901) CONS NULL)                                      
 when binding SB-VM::DIMENSIONS
    [Condition of type TYPE-ERROR]

Solution

  • * evaluates to the last evaluated value, which is that of the symbol *Y*, which is an array #(2 3 55).

    But make-array expects its first argument to specify "dimensions" of the array it creates:

    make-array dimensions &key element-type initial-element initial-contents
    adjustable fill-pointer displaced-to displaced-index-offset

    => new-array

    Arguments and Values:

    dimensions---a designator for a list of valid array dimensions.

    ... a list.

    (emphasis mine). Some lists are nulls, some are conses. But not arrays symbols.

    And since it expects a list designator, i.e.

    a non-nil atom (denoting a singleton list whose element is that non-nil atom) or a proper list (denoting itself),

    the other possibility is a whole number.