title: Define a constant array of struct known at compilation-time
body: <p>In my program I have constant strings, the values are known at compilation time. For each offset there are currently 2 associated strings. I first wrote the following code:</p>
  <pre><code>(eval-when (:compile-toplevel :load-toplevel :execute) ;; BLOCK-1
    (defstruct test-struct
      str-1
      str-2))
  
  (eval-when (:compile-toplevel) ;; BLOCK-2
  
    (defparameter +GLOBAL-VECTOR-CONSTANT+ nil) ;; ITEM-1
  
    (let ((vector (make-array 10
                              :initial-element (make-test-struct)
                              :element-type    'test-struct)))
      (setf (test-struct-str-1 (aref vector 0)) &quot;test-0-1&quot;)
      (setf (test-struct-str-2 (aref vector 0)) &quot;test-0-2&quot;)
  
      (setf +GLOBAL-VECTOR-CONSTANT+ vector)))
  
  (format t &quot;[~A]~%&quot; (test-struct-str-1 (elt +GLOBAL-VECTOR-CONSTANT+ 0)))
  (format t &quot;[~A]~%&quot; (test-struct-str-2 (elt +GLOBAL-VECTOR-CONSTANT+ 0)))
  </code></pre>
  <p>This seems to work as it returns the following:</p>
  <pre><code>[test-2-1]
  [test-2-2]
  </code></pre>
  <p>In <code>BLOCK-1</code> the <code>struct</code> containing the data is defined, for <code>compile-time</code>, <code>load-time</code> and <code>execute-time</code>. In <code>BLOCK-2</code>, the code which create a vector and sets the values is executed, at <code>compile-time</code>.</p>
  <p>But I have the following concerns:</p>
  <ul>
  <li>This code seems unnecessary verbose</li>
  <li>The strings are stored in a <code>structure</code></li>
  <li>I need to manually set the <code>offset</code> of each values (<code>(aref vector 0)</code>, <code>(aref vector 1)</code>, etc).</li>
  <li>When I set <code>ITEM-1</code> inside <code>BLOCK-1</code> instead of <code>BLOCK-2</code> I get an error in <code>SBCL</code> which I don't understand</li>
  </ul>
  <p>What is the idiomatic way to define complex constants in <code>Common Lisp</code>?</p>