On Fri, 6 Jun 2003 21:22:13 +0100, Rob Dixon <[EMAIL PROTECTED]> 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?
>
> Rob


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.

Rob

I'm sorry that I misinterpreted your question. I don't know of a property of map that would justify the overhead in any situation.


Katy


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



Reply via email to