尝试一一打印数组元素时在CLISP中遇到错误“变量AREF没有值”

时间:2018-09-27 23:45:56

标签: lisp common-lisp clisp

我试图在CLISP中打印数组的值,我写了以下函数:

(setq x (make-array '5 :initial-contents '(a b c d e)))
(loop for i from 0 to 4 do (write aref x i))

但是我遇到了错误

*** - PROGN: variable AREF has no value 
      The following restarts are available:
 USE-VALUE      :R1      Input a value to be used instead of AREF.
 STORE-VALUE    :R2      Input a new value for AREF.

我对CLISP完全陌生,却不明白为什么会出现上述错误。

1 个答案:

答案 0 :(得分:5)

AREF函数,而不是变量。 您缺少一组括号:(aref x i)

(loop for i from 0 to 4 do (write (aref x i)))

或者只是

(loop for e across x do (write e))

PS。请注意,write是一个 级别较低的功能。 您可能要使用printprinc的变体。