<SeanTAllen>
there's no deep clone. for there to be one, everything that goes into an Array would have to be cloneable. Not a limitation we've been able to justify on Array.
<SeanTAllen>
iterating the values is what you would need to do.
<SeanTAllen>
question though... do you need an Array ref?
<wryun>
Thanks Sean - the 'buffer' needed to be mutable in the way I was using it (hence the ref), and I was surprised there was no trivial way to convert a mutable buffer into a string without explicitly iterating over the elements. Wanted to make sure I wasn't missing something, which it sounds like I wasn't.
<wryun>
In the end I ended up with something entirely different:
<wryun>
(let to_send, let new_buffer) = (consume data).chop(n)
<wryun>
let old_buffer = _buffer = consume new_buffer
<wryun>
Sorry for not using the mailing list and following the directions!
<wryun>
I can answer it myself later.
<wryun>
I still need to think a little bit more about why iterating over the values works (i.e. manual deep clone) but it's not possible for array to implement a deep clone.
<wryun>
(well, not even a deep clone - I mean, it's just a clean copy of the array, right?)
<SeanTAllen>
Array has clone but you'll get a `ref` back. Deep clone would require everything to be cloneable.
<SeanTAllen>
With clone, its a shallow copy
<wryun>
So, is it always possible to copy the array by iterating and not by calling a method? Or does it depend on what's in the array?
<SeanTAllen>
When you iterate, you can do the proper thing to copy.
<SeanTAllen>
In your case tho, you needed to iterate because `clone` would give you back a `ref` which isn't what you wanted.
<SeanTAllen>
There's some ideas on being able to have different methods for different return refcaps but that is just some ideas being kicked around and is a long way from being anything substantial.
<wryun>
I assume the key point is that the 'proper thing' differs depending on the type, right?
<SeanTAllen>
Yes.
<wryun>
Right, makes sense - thanks for you help!
<SeanTAllen>
Every type could have a "clone" or "deep clone" method on it to do the right thing.
<SeanTAllen>
That would be one way to address.
<SeanTAllen>
But that's not something that I think anyone has a particular stomach for at this time.
<SeanTAllen>
And even if they did, it wouldn't address your issue which was "i want something that isnt a ref back"
<wryun>
So in theory the stdlib could have some methods for copying arrays of primitives.
<wryun>
Or would I still be stuck with a ref?
<wryun>
(that could return an iso, right?)
<SeanTAllen>
Someone could probably write up enough primitives to do the right thing.
<SeanTAllen>
Sorry have to run. My flight is boarding soon.