[Seaside] Backtracking with collections

David Buck david at simberon.com
Sat Mar 15 20:38:10 UTC 2008

Lukas Renggli wrote:
>>  | array |
>>  array := #(1 2 3 4 5) copy.
>>  array restoreFrom: #(4 5 6) copy.
>>  array
>>  --->  #(4 5 6 nil nil)
>>  | array |
>>  array := #(1 2 3) copy.
>>  array restoreFrom: #(4 5 6 7 8) copy.
>>  array
>>  --> Index out of bounds exception
> This is not how the backtracking API works, #copy is not part of it.
> Have a look at WABacktrackingTest:

Just a note:  The "copy" above was just a VisualWorks work-around to get 
around immutable literal objects.  I could have said "beMutable" or I 
could have created the arrays using with:with:with: etc.  For the 
purpose of this problem, you can ignore the copy.
>>  Michael Lucas-Smith tried it in Squeak and the first example produced
>>  #(4 5 6 4 5) and the second one produced: #(4 5 6).
> Arrays are considered to be immutable in size in Squeak.
And I think Arrays should be considered immutable in size.  This 
mechanism isn't designed for arbitrary become: calls and shouldn't need 
to worry about that.  My main concern was actually OrderedCollection.  
In VW, OrderedCollection contains named and indexed instance variables 
and grows using become:.  Maybe not the best implementation, but that's 
what's there.  This mechanism would have trouble with that unless you 
make a special case for OrderedCollection.
>>  To do this properly, you'd first have to create a new collection of the
>>  proper size, use a become: to change the original collection back, then
>>  restore it to the proper values using the existing restore mechanism.
>>  Am I out to lunch on this one or does this change need to be made?
> You need to implement #snapshotCopy and #restoreFromSnapshot: in
> OrderedCollection according to your internal implementation. I guess
> #snapshotCopy  just returns a shallow copy (the default), while
> #restoreFromSnapshot: can do a #become: of a copy of the snapshot to
> the one you want to restore. Or something like that.
> Lukas
This sounds reasonable.  The snapshotCopy method should be fine as is.  
It's the restoreFromSnapshot: that would need to be implemented in 

David Buck

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20080315/0e8a11cd/attachment.htm

More information about the seaside mailing list