From: Mohamed A. Jeragh
Subject: Help!!!: Variable arrays
Date: 
Message-ID: <325716EA.4B4@worldnet.att.net>
Hi,
I have the following code in my program:

(defvar max 100)

(defun db-create ( x &rest xlist)
     (setf j (length xlist))
     (defvar x (make-array '( j max))) ;I tried it without '
     (dotimes (i 0 (- j 1))
              (setf (aref x i 0) (nth i xlist))
     );dotimes
);db-create                              

What is wrong here? I want to create 2-dim array at run-time?

Thanks for your help in advance,
--MJ
From: DDL
Subject: Re: Help!!!: Variable arrays
Date: 
Message-ID: <53bl24$c0j@decius.ultra.net>
"Mohamed A. Jeragh" <········@worldnet.att.net> wrote:
>
> Hi,
> I have the following code in my program:
> 
> (defvar max 100)
> 
> (defun db-create ( x &rest xlist)
>      (setf j (length xlist))
>      (defvar x (make-array '( j max))) ;I tried it without '
>      (dotimes (i 0 (- j 1))
>               (setf (aref x i 0) (nth i xlist))
>      );dotimes
> );db-create                              
> 
> What is wrong here? I want to create 2-dim array at run-time?
> 
> Thanks for your help in advance,
> --MJ
Well, first you should not be passing in x as a parameter and then
trying to DEFVAR it.  Second, your DOTIMES loop is malformed.  DOTIMES
will loop from zero up to (but not including) j already, so 
you don't need (- j 1).

See if this works better, it creates and returns the array, which you
can then bind to a variable at runtime:

(defun db-create (&rest xlist)
   (let* ((j (length xlist))
          (db (make-array '( j max)))) 
      (dotimes (i j)
               (setf (aref db i 0) (nth i xlist))
      );dotimes
  db ); returns the created array
 );db-create  


Then use it at runtime as:

(defvar x (db-create <element entries>))