Search code examples
lispcommon-lispclisp

Getting error "variable AREF has no value " in CLISP while trying to print array elements one by one


I am trying to print the value of an array in CLISP, I wrote below function:

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

But I am getting error

*** - 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.

I am totally new to CLISP and not getting why I am getting the above error.


Solution

  • AREF is a function, not a variable. You are missing a set of parentheses around it: (aref x i):

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

    or just

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

    PS. Note that write is a relatively low level function. You probably want to use a variant of print or princ.