Oh, BTW, just an additional quote from the Camel Book
I've no idea when that edition was revised; but if it was any time in the last 8 or so years, the revision was lacking.
Neither map nor grep "throw away their return values" when used in a void or scalar context; they simply do not produce that list.
I don't recall which version this was changed for; but it has been so for long enough that anyone leveling charges of "the inefficiency of map in a void context" can only be be cargo-culted repetition of something you've heard or read; not based upon actual experience.
Ie. Don't level a charge until you've tested it for yourself; rather than just parroting what you've heard or read others say.
And I upvoted your post despite a couple of things I don't like to much.
Don't! If you don't like what I say, don't upvote.
Now to those things you apparently didn't like:
And I was only trying to offer a possible reason why the OP asked the question in the first place.
Do you think that your guess as to his reasoning is likely to be any more definitive than my guess?
Yeah, I am more limited than you, sorry about that.
If you set out to be offended; you likely will be; but twisting my words to achieve that happy state is less rhetoric, more ....
I didn't say you were limited; I said your expectations were. And the latter is in no way a personal attack; just a statement of fact based upon your own expression of those expectations.
You expect to see map used to produce a new list from a list. This may be because you've come from a background (some other language; possibly a functional one) where that is the only way their (equivalent of) map can be used. Maybe because that is what you've read that it does. Or maybe it just the only way you've ever used it. None of these is an insult. None of these is a personal attack.
Perl's implementation of many widely used constructs is more flexible than their equivalents in other languages. That is in big part what makes Perl so useful and effective.
In this case, map embraces rather than decries the ability to modify the iterated list in place -- what you called a "side-effect" -- through the use of aliasing of the origin of the list. That allows Perl to achieve efficiencies that would be difficult (Haskell's unsafe* functions) or impossible (Clean/Miranda/Erlang) in other languages.
Labeling others' arguments does not make the label true. Besides, this is just rhetorics, falling short of a proper intellectual argument.
Dealt with above, but to reiterate.
Performance:
[0] Perl> cmpthese -3,{a=>q[@a = map $_*1, @a],b=>q[map $_*=1, @a],c=> +q[$_*=1 for @a] };; Rate a c b a 2.88/s -- -67% -67% c 8.64/s 200% -- -2% b 8.86/s 208% 3% --
If you repeat an idea without having tested it for yourself -- that's cargo-cult.
When the label applied is correct; that is perfectly good "intellectual argument". It's a fact.
In reply to Re^5: Write code diferently
by BrowserUk
in thread Write code diferently
by madM
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |