Make every element of the original array a 'reference to a cell'. Then create a shadow array with the same cells but the elements reversed. Changing the value in a cell will change the array contents.
(defun make-celled-array (m n init)
(let ((array (make-array (list m n))))
(dotimes (i m)
(dotimes (j n)
(setf (aref array i j) (list init)))) ; (list init) makes a 'cell'
array))
(defun celled-array-ref (array m n)
(car (aref array m n)))
(defsetf celled-array-ref (array m n) (val)
`(setf (car (aref ,array ,m ,n)) ,val))
(defun shadow-celled-array (ca)
(let ((m (array-dimension ca 1)) ; swapped
(n (array-dimension ca 0)))
(let ((array (make-array (list m n))))
(dotimes (i m)
(dotimes (j n)
(setf (aref array i j) (aref ca j i)))) ; swapped
array)))
Use:
* (defvar a1 (make-celled-array 2 4 1))
A1
* (setf (celled-array-ref a1 0 3) 10)
10
* a1
#2A(((1) (1) (1) (10)) ((1) (1) (1) (1)))
* (defvar a2 (shadow-celled-array a1))
A2
* a2
#2A(((1) (1)) ((1) (1)) ((1) (1)) ((10) (1)))
* (celled-array-ref a2 3 0)
10
* (setf (celled-array-ref a2 3 0) 100)
100
* (celled-array-ref a1 0 3)
100