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 [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
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 <[hidden email]>: > 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 > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Thanks
Cédrick...you are right; I don't know how I missed that one right there in the Method Finder...I can't seem to make your ctrl+alt+w trick work, though! Maybe I don't have something installed?
Rob On Fri, May 30, 2008 at 7:08 PM, cdrick <[hidden email]> wrote: Hi Rob _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
> I can't seem to make your ctrl+alt+w trick
> work, though! Maybe I don't have something installed? oups sorry this is alt + shift + w or alt + W go in the world menu > help > command-key help to see the plethora of available shortcuts hth Cédrick _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
cdrick schrieb:
>> I can't seem to make your ctrl+alt+w trick >> work, though! Maybe I don't have something installed? > > oups sorry this is alt + shift + w or alt + W > > go in the world menu > help > command-key help to see the plethora > of available shortcuts > > hth > > Cédrick > > > ------------------------------------------------------------------------ > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners Hi ---, For such problems there is another nice tool called Method Finder. There you can insert all your objects, parameters and the result and Smalltalk try to find a proper method for your needs. I have found the swap method with the following message: #(a b). 1. 2. #(b a). From my Array (#(a b)) i'm looking for a method with two parameters(index) to get the result of #(b a) Kind regards, Michael _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
sweet :) haven't used it that way... nice to know. Thanks Michael _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Mon, Jun 2, 2008 at 8:07 AM, cdrick <[hidden email]> wrote:
Very nice...so, from the Method Finder help: "Or, use an example to find a method in the system. Type receiver, args, and answer in the top pane with periods between the items. 3. 4. 7" do you put a number for EACH parameter...meaning if we were looking for a 3 parameter method we would put a 1. 2. 3. between the receiver and the expected answer? Thanks...I've seen the blurb in the Method Finder, but never quite figured it out! Rob _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>>>>> "Rob" == Rob Rothwell <[hidden email]> writes:
Rob> "Or, use an example to find a method in the system. Type receiver, args, Rob> and answer in the top pane with periods between the items. 3. 4. 7" Rob> do you put a number for EACH parameter...meaning if we were looking for a 3 Rob> parameter method we would put a 1. 2. 3. between the receiver and the Rob> expected answer? If I recall, it tries all combinations, repeatedly picking one thing as the object, another as the result, then any remaining items in all orderings as parameters. So, 3. 2. 1. would still find 1 + 2 = 3. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <URL:http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |