From: Patrick Jarjoui
Subject: defvar and symbol error
Date: 
Message-ID: <8frits$tn1$1@news.crihan.fr>
hello everybody,

         Can anybody help me in this sentence

(loop as x from 1 to 450
  do (defvar (read-from-string (format nil "*truck~A*" x)))
)

it reurns me an error

Error: the value of SYMBOL is
       (READ-FROM-STRING (FORMAT NIL "*truck~A*" x)), which is not of
       type SYMBOL.
  [condition type: TYPE-ERROR]

Restart actions (select using :continue):
 0: supply a new value for SYMBOL.
 1: Return to Top Level (an "abort" restart)
[1] USER(104):

all i want to do is create a lot of variables  to use them later in my
program

Thanks

Patrick

From: Knut Anders Hatlen
Subject: Re: defvar and symbol error
Date: 
Message-ID: <86zopqr9ef.fsf@stjernegris.hatlen.no>
Patrick Jarjoui wrote:

> hello everybody,
> 
>          Can anybody help me in this sentence
> 
> (loop as x from 1 to 450
>   do (defvar (read-from-string (format nil "*truck~A*" x)))
> )
> 
> it reurns me an error
> 
> Error: the value of SYMBOL is
>        (READ-FROM-STRING (FORMAT NIL "*truck~A*" x)), which is not
>        of type SYMBOL.
>   [condition type: TYPE-ERROR]

DEFVAR doesn't evaluate its first argument. Try this macro instead:

(defmacro deftrucks (n)
  `(progn
    ,@(loop as x from 1 to n
	    collect `(defvar ,(intern (format nil "*TRUCK~A*" x))))))

(deftrucks 450)

-- 
Knut Anders
From: Frode Vatvedt Fjeld
Subject: Re: defvar and symbol error
Date: 
Message-ID: <2hwvkubuc9.fsf@dslab7.cs.uit.no>
"Patrick Jarjoui" <···············@insa-rouen.fr> writes:

> all i want to do is create a lot of variables to use them later in
> my program

If you look at the documentation for DEFVAR, you'll see it's a special
form, and the name parameter is not evaluated. You could use a macro
in order to programatically create DEFVAR-forms at compile-time, maybe
something like this:

(defmacro make-many-defvars (fmt num initial-value)
  (cons 'progn
        (loop for x from 1 to num
           collect `(defvar ,(intern (format nil fmt x)) ,initial-value))))

(make-many-defvars "*truck~A*" 450 'value)

Now try to macroexpand that last form to see its effect.

-- 
Frode Vatvedt Fjeld
From: Aaron Crane
Subject: Re: defvar and symbol error
Date: 
Message-ID: <djd7mmps2v.fsf@planet.dcs.ed.ac.uk>
In article <············@news.crihan.fr>,
"Patrick Jarjoui" <···············@insa-rouen.fr> writes:
> (loop as x from 1 to 450
>   do (defvar (read-from-string (format nil "*truck~A*" x))))
> 
> all i want to do is create a lot of variables to use them later in my
> program

Other people have pointed out why your code doesn't work, and how it can be
made to.  But if all you want to do is create lots of variables, why not use
something like this:

    (defvar trucks (make-array 450))

This declares a single variable TRUCKS, and makes it an array of 450
elements, which is almost certainly what you want.  Using an array instead
of 450 individual variables will enable you to operate on all of them -- and
without naming them one at a time.  If you aren't familiar with the use of
arrays in Lisp, then note that

    (aref trucks n)

evaluates to the Nth element of TRUCKS (starting from 0), and

    (setf (aref trucks n) expr)

sets the Nth element of TRUCKS to EXPR.

-- 
Aaron Crane   <···········@pobox.com>   <URL:http://pobox.com/~aaronc/>
 ** Please send on-topic followups by Usenet, not email **