[Newbies] Exchanging Elements in an OrderedCollection

cdrick cdrick65 at gmail.com
Fri May 30 23:08:30 UTC 2008


Hi Rob

There is one method in SequenceableCollection (and in Set) that does
what you want (same implementation as yours)...

SequenceableCollection >>swap: oneIndex with: anotherIndex

I found it by using ctrl+alt+w when swap selected (one of my favorite
shortcut - for selectors containing it)

Cheers

Cédrick

2008/5/31 Rob Rothwell <r.j.rothwell at gmail.com>:
> This is a curiosity question that will hopefully help me understand the
> Squeak *system* better.
>
> I have an Aida application in which I find myself doing a lot of list
> manipulation, and given the reputation Smalltalk has for the strength of
> it's collection classes, I felt sure I would find a method SOMEWHERE that
> exchanged two elements.
>
> So...am I just no good at finding what I'm looking for (swap, exchange,
> move?), or is it because it is so simple to write something like
>
> exchange: index1 and: index2
>     |temp|
>     temp := self at: index1.
>     self at: index1 put: (self at: index2).
>     self at: index2 put: temp.
>
> that no one would even think of needing to include such behavior?
>
> Again, just wondering so I can "measure" my understanding of how little I
> know and better gauge whether I think I can find an answer from the system
> itself...
>
> Of course, the answer is probably "why don't you just..." along with a
> single line...!
>
> Thanks,
>
> Rob
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>


More information about the Beginners mailing list