IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Re: Isn't there a reject message?
yeah, but it's still 2 messages...
Would be more elegant to have a "split:" mesage: things that are removed get gathered in another collection.

New Yes
use #removeAllSuchThat: aBlock

Like most Smalltalk collection methods, it returns something useful. In this case, it removes all objects for which aBlock is true; it also returns a collection of what was removed

======================
|colToGo |

colToGo := coll removeAllSuchThat: [: each | each stays not]
======================

This is present in VisualWorks; I haven't checked other implemtations. If not available on your platform, I can post the code for the method

Take care,

Jay O'Connor

"Going places unmapped
to do things unplanned
to people unsuspecting"
New Yes... Yes! Yes!
:)

Thanks for the hint.
I am using VisualWorks non-commercial.
New So how's it done?
I can see the stripped members being sent back as the result of the function. The only way I can see that the function would strip the original collection is if it uses a become: method. So is that how it's done?
New I don't get it
It just loops through itself and anything that matches the block gets added to a temp collection to be returned and removed

Do you mean how do you remove from within a loop? How do you change a collection while iterating over the collection? The loop internal to the method actually sets up an loop over the indices of the collection. The element to be removed used removed using it's index (#removeByIndex: ) #removeByIndex: just goes from the given index to end, scooting every element up one position and then cutting off the last element
Jay O'Connor

"Going places unmapped
to do things unplanned
to people unsuspecting"
New Never mind...
...been studying too many functional languages, and for some reason I keep thinking that collections are immutable objects in ST. Must go back and study Squeak some more.

BTW, the message that you gave for VW doesn't seem to be standard in Squeak.
New heh heh heh
I have that problem in Icon, too. Collections and variables are generally intuitively mutable wherever you put them :-). Sometimes makes for very very elegant code.

Wade.

"All around me are nothing but fakes
Come with me on the biggest fake of all!"

New Standard or not?
Did you look in List or OrderedCollection? That's where it is.
     Smalltalk Question - (Arkadiy) - (16)
         Isn't there a reject message? - (static) - (8)
             Re: Isn't there a reject message? - (Arkadiy) - (7)
                 Yes - (Fearless Freep) - (6)
                     Yes... Yes! Yes! - (Arkadiy)
                     So how's it done? - (ChrisR) - (4)
                         I don't get it - (Fearless Freep) - (3)
                             Never mind... - (ChrisR) - (2)
                                 heh heh heh - (static)
                                 Standard or not? - (Arkadiy)
         Not aware - (ChrisR) - (1)
             Re: Not aware - (Arkadiy)
         Speaking of smalltalk - (wharris2) - (4)
             Re: Speaking of smalltalk - (tuberculosis)
             Re: Speaking of smalltalk - (Arkadiy) - (2)
                 Fortunately - (Fearless Freep) - (1)
                     I don't think _I_ could do without. - (Arkadiy)

Rather in the way of gilding the lily, and not to be encouraged.
98 ms