Previous: , Up: Dynamic-Extent Declarations   [Contents][Index]


2.26.3 list, list*, and cons

New conses allocated by list, list*, or cons which are used to initialize variables can be allocated from the stack if the variables are declared dynamic-extent. In the case of cons, only the outermost cons cell is allocated from the stack; this is an arbitrary restriction.

(let ((x (list 1 2))
      (y (list* 1 2 x))
      (z (cons 1 (cons 2 nil))))
  (declare (dynamic-extent x y z))
  ...
  (setq x (list 2 3))
  ...)

Please note that the setq of x in the example program assigns to x a list that is allocated from the heap. This is another arbitrary restriction that exists because other Lisps behave that way.