Common Lisp the Language, 2nd Edition

Next: The Evaluator Up: Structures of Explicitly Previous: Named Structures

## 19.7.3. Other Aspects of Explicitly Specified Structures

The `:initial-offset` option allows one to specify that slots be allocated beginning at a representational element other than the first. For example, the form

    (defstruct (binop (:type list) (:initial-offset 2))
      (operator '? :type symbol)
      operand-1
      operand-2)

would result in the following behavior for `make-binop`:

    (make-binop :operator '+ :operand-1 'x :operand-2 5)
       => (nil nil + x 5)

    (make-binop :operand-2 4 :operator '*)
       => (nil nil * nil 4)

The selectors `binop-operator`, `binop-operand-1`, and `binop-operand-2` would be essentially equivalent to `caddr`, `cadddr`, and `car` of `cddddr`, respectively. Similarly, the form

    (defstruct (binop (:type list) :named (:initial-offset 2))
      (operator '? :type symbol)
      operand-1
      operand-2)

would result in the following behavior for `make-binop`:

    (make-binop :operator '+ :operand-1 'x :operand-2 5)
       => (nil nil binop + x 5)

    (make-binop :operand-2 4 :operator '*)
       => (nil nil binop * nil 4)

If the `:include` is used with the `:type` option, then the effect is first to skip over as many representation elements as needed to represent the included structure, then to skip over any additional elements specified by the `:initial-offset` option, and then to begin allocation of elements from that point. For example:

    (defstruct (binop (:type list) :named (:initial-offset 2))
      (operator '? :type symbol)
      operand-1
      operand-2)

    (defstruct (annotated-binop (:type list)
                                (:initial-offset 3)
                                (:include binop))
      commutative associative identity)

    (make-annotated-binop :operator '*
                          :operand-1 'x
                          :operand-2 5
                          :commutative t
                          :associative t
                          :identity 1)
       => (nil nil binop * x 5 nil nil nil t t 1)

The first two `nil` elements stem from the `:initial-offset` of `2` in the definition of `binop`. The next four elements contain the structure name and three slots for `binop`. The next three `nil` elements stem from the `:initial-offset` of `3` in the definition of `annotated-binop`. The last three list elements contain the additional slots for an `annotated-binop`.

Next: The Evaluator Up: Structures of Explicitly Previous: Named Structures