John W . Krahn wrote:
> On Friday 06 June 2003 13:22, Rob Dixon wrote:
> > Katy Brownfield wrote:
> > > On Fri, 6 Jun 2003 18:16:26 +0100, Rob Dixon
> > > <[EMAIL PROTECTED]>
> > >
> > > wrote:
> > > > John W. Krahn wrote:
> > > > > Mark Anderson wrote:
> > > > > > B) You should NEVER use map in a void context.  map works
> > > > > > very hard to build up it's return value, so there should be
> > > > > > an assignment (=) operator to the left of your map call
> > > > > > almost always, otherwise all of that work is wasted.
> > > > >
> > > > > I would never say NEVER as there are some situations where it
> > > > > may be appropriate, just like there are some situations where
> > > > > goto is appropriate.
> > > >
> > > > Sure, but I can't for the moment think of any difference between
> > > >
> > > > foreach (LIST) BLOCK
> > > > or
> > > > EXPRESSION foreach LIST
> > > >
> > > > and
> > > >
> > > > map BLOCK LIST
> > > > or
> > > > map EXPRESSION, LIST
> > > >
> > > > in void context. Any thoughts?
> > >
> > > Mark explained the difference. map has the overhead of building the
> > > list that it returns. foreach doesn't. In Kevin's example a list
> > > containing "01" .. "12" is created and never used. It's
> > > inefficient.
> >
> > Thanks Katy, but John was saying that there were "some situations
> > where it may be be appropriate [to use map in a void context]". I
> > could think of none, since those constructs that I posted using
> > 'foreach' seemed to do exactly the same thing without the overhead
> > that you describe. I wondered if John (or anybody) knew of a
> > difference that I didn't.
>
> Well, to quote Larry Wall[0] (you all know who he is don't you):
>
> "The argument against using an operator for other than its
> primary purpose strikes me the same as the old argument that you
> shouldn't have sex for other than procreational purposes. Sometimes
> side effects are more enjoyable than the originally intended effect."

Sometimes, though, the side-effects spoil all the fun ;-)

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to