Problems with ST/X and Solutions

BOSS & SortedCollection?

Postby duetto » 17. Feb 2010, 16:17


stx doesn't allow a sortedcollection to be stored using BOSS.

i've run into this problem on 2 occasions. in one case, in my application, i got around it by using an ordered collection. in the other case, Minnestore, it's much more complicated to workaround.

is there any way to fix/allow a sorted collection to be stored using BOSS?

john cummings
Posts: 22
Joined: 28. Sep 2009, 02:43

Re: BOSS & SortedCollection?

Postby jan_vrany » 17. Feb 2010, 18:15


the problem is that BOSS cannot store blocks since they keeps reference to a context objects from current thread.
There is no way to store blocks.
Blocks are used as comparators within the SortedCollection (sortBlock instvar), so that's why you cannot store sorted collection.

However, SortedCollection does not require sortBlock to be a block. It could be anything that responds to
value:value:. You may create a new class, say Comparator, then add a instance method
Code: Select all
value: a value: b
      "do whatever your sortblock do, for instance:"
      ^ a < b

And then create the SortedCollection with instance of Comparator as sortBlock, lke this:

Code: Select all
things := SortedCollection sortBlock: Comparator new.

Now the collection things contains no blocks and thus could be bossed out. Well, it's a bit more
work, but should work.
Posts: 28
Joined: 10. Dec 2008, 12:37

Return to Troubleshooting

Users browsing this forum: No registered users and 2 guests

Design by GB