[Seaside] Backtracking with collections

David Buck david at simberon.com
Sat Mar 15 13:19:28 UTC 2008

I was trying to use the #states method to record the state of a 
collection. It wasn't working properly for various reasons, but in the 
process, I found that the register: and restoreFrom: mechanism doesn't 
work for collections if become: was used to change the collection size 
between the register: and the restoreFrom:.

This happens naturally in OrderedCollections (this is the way they grow 
- at least in VW).

Try these examples:

| array |
array := #(1 2 3 4 5) copy.
array restoreFrom: #(4 5 6) copy.

--->  #(4 5 6 nil nil)

| array |
array := #(1 2 3) copy.
array restoreFrom: #(4 5 6 7 8) copy.

--> Index out of bounds exception

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).

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?

David Buck

More information about the seaside mailing list