def参数的使用

Usage of defparameter

不知道是不是因为我对defparameter宏的核心内容不了解

所以,这给出了一个奇怪的错误。我开始于:

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

一切都很好,但是接下来:

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

给出了一个错误,我根本不明白:

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

* 计算最后一个计算值,即 符号 *Y* 的值,它是一个数组 #(2 3 55).

但是 make-array 期望它的第一个参数指定数组的“维度” 创建:

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.

...一个列表.

(强调我的)。有些列表是 nulls,有些是 conses。但不是 arrays 符号。

并且因为它需要一个列表 designator,即

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

另一种可能是整数。

CL-USER 28 > (defparameter *y* #(2 3 55))
*Y*

CL-USER 29 > *
*Y*

*的值为上次顶级评价结果的第一个值

在您的例子中,值是 *y* - 一个符号。然后你用那个符号作为第一个参数调用 MAKE-ARRAYMAKE-ARRAY 不需要符号 - 因此错误:

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

错误的意思是:符号 *y* 既不是数字(具有一定的最大长度)也不是列表。请记住 *y* 是评估 *.

的结果

关于 mod in the error message, that is a type specifier: (mod 4611686018427387901) means "an integer between 0 and 4611...", the big number being the array-dimension-limit