On Fri, 26 Oct 2001, Justice, Randy -CONT(DYN) wrote:
> Can one have a list composed of arrays and lists?
You can have a heterogeneous list composed of any mixture of Lisp
> I'm having a problem.. It seems to be related to a list that contains 3-D
> arrays and lists.
> My list seems to change without a reason...
Without seeing your code, I can offer you the following hypothesis:
perhaps you are destructively manipulating the list. Destructive
manipulation of lists and other objects can cause a change in one
object to mysteriously propagate to another object. That happens
because in Lisp, objects often share parts of their structure with other
objects in order to save space and time. A change to the substructure
affects all objects which share it.
For instance if you create a list and bind it to symbol x like this:
(setf x (list 'b 'c 'd))
and then you use this list to create another one and bind it to y:
(setf y (cons 'a x))
you now apparently have two lists (b c d) and (a b c d), but they share
the three cells which make up the trailing portion (b c d). If
you change something in that trailing portion, the change will affect
Note that storing values into arrays is destructive manipulation,
and that arrays are manipulated by reference. It's easy to end up
with multiple references to the same array in circumstances that
call for distinct array objects, leading to surprising results.
(setf x (make-array 3)) ;; make array, bind to x
(setf y x)
(setf (aref x 1) 42) ;; modify x
x => #(nil 42 nil)
;; x modified okay
y => #(nil 42 nil)
;; What??? Why did y change? It must be the same array as x.
(eq x y) => T
;; eq test confirms our suspicion:
;; the values of x and y are implemented as the same array object!