<sandia.gov at svspire> wrote:
<well.com at [mlb> wrote about adjust-array being guaranteed to copy the
array in one particular case.]
> It's not clear to me from reading the hyperspec that this is always
> guaranteed, and I trust the hyperspec more than CLtL. However, the
> hyperspec _does_ offer an alternative guarantee involving
> adjustable-array-p.
The adjust-array guarantee looks pretty solid to me:
A is displaced to B before the call, but not displaced afterward.
(adjust-array A ... :displaced-to B)
(adjust-array A ... :displaced-to nil)
A gets a new ``data region,'' and contents of B are copied into it
as appropriate to maintain the existing old contents; additional
elements of A are taken from initial-element if supplied. However,
the use of initial-contents causes all old contents to be discarded.
(From
<http://www-2.cs.cmu.edu/Groups/AI/html/hyperspec/HyperSpec/Body/fun_adjust-array.html>.
Also see
<http://groups.google.com/groups?selm=sfwwwmgwhuh.fsf%40world.std.com>,
where at least someone else has come to the same conclusion.)
Ah. Unfortunately, issues are not part of the spec, and are only
there to give background and help you to understand the original
intent.
So I think that this code of Marc's is probably the easiest, and is
correct:
(defun copy-array (array)
(let ((dims (array-dimensions array)))
(adjust-array
(make-array dims :displaced-to array)
dims)))
John Wiseman
__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com