On 10/6/05, David A. Black <dblack / wobblini.net> wrote:
> On Fri, 7 Oct 2005, Jacob Fugal wrote:
> > On 10/6/05, David A. Black <dblack / wobblini.net> wrote:
> >> If you select! elements from an array (dangerous/destructive select),
> >> those elements should be *removed* from the array.  It's like
> >> selecting people from the audience to come onto the stage: they are
> >> removed from the audience.  The audience is not reduced to being just
> >> them.
> >
> > Hmm, I'd disagree. After all, we're sending the message to the array
> > aren't we?
>
> That's true across the board, though; it's not a determinant of what
> happens when we send a message.

But the exclamation mark (to me) says, "Do this to yourself, Mr.
Array."  When you tell the array to reject!, it throws away the
matches and says, "Here's my state now, what next?" or "Whoops, I
didn't do anything."  I think the same should be applicable for
select.

> Or you could look at it as: "Give me (permanently) all your shiny
> apples!"
>
>    my_apples = johnny.select! {|a| a.shiny? }
>
> So now my_apples has them, and johnny doesn't.  Mind you, I'm not
> eager to see my version in the language either.  I don't like the bang
> method not returning the receiver.  But I don't like the semantics, in
> this case, when it does.  (And the find_all! thing is a further sign
> that this method was not meant to have a bang version.)

Well, I think we should have a Array#gimme and Array#gimme! to
differentiate from select!.  Then you would have your functionality,
while select! would say (as I think it should), "select these
(permanently)."

By your logic, reject! is also wrong.  johnny.reject! should reject
the items, and then give them to you, which is the same as your
select!.  That's not what it does, though...

Regarding find_all!, Just because they're synonyms, doesn't mean they
have to both have the !.  If everyone instantly associates select and
find_all together because they're synonyms, why have them both?  I
don't think they do.  People see 'find' and they think, "But I want to
find everything, not just one," and then they come upon find_all. 
With select and reject, it says, "pick these," and "pick everything
but these."  Just because they end up meaning the same thing, doesn't
mean they have the same connotations.

find and find_all are the benign operations.  select and reject are more risque.

> I think there's been talk in the past of delete_unless.  delete_if is
> not quite the same as reject! (one of them returns nil if nothing's
> found; the other returns an array, I believe).

I believe you are correct (about reject! and delete_if, I don't know
about the others).

In all honesty, I don't care what it's called, but reject! feels like
it should have an opposite.

--
Rob (Pontificating at a Late Hour)