NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Re: (Score:1)
Re: (Score:1)
undef.Why "item count"? Least likely! (Score:2)
I think a much more interesting thing would be a floating point value between 0 and 1 of how many adjacent pairs of items already meet the sort criteria, so "1..5" would be 1, but "reverse 1..5" would be 0.
Re: (Score:1)
That sortedness factor you propose sounds really useless.
0 + sort qw( 1 3 5 7 9 0 2 4 6 8 10 )would return 0.9. But what am I supposed to conclude from that? The list is certainly not 90% sorted, nor can I think of any other way in which this metric might be useful.OTOH, returning the item count would allow parity for
with
and
in scalar context.
And item count in scalar context is actually the majority among functions that take a l [perlmonks.org]
Re: (Score:1)
I said "interesting", not "useful" (Score:2)
Maybe I'm the only Perl person on the planet that does not presume "length of list in scalar context" for every list-returning operation, but I think it's a fair starting place.
From a practical perspective, channelling Larry here for a moment (which after nearly two decades, I'm getting only slightly better at),
Re:I said "interesting", not "useful" (Score:1)
Lack of parity with
mapandgrepmeans that implementation details leak out of a function. The caller needs to know whether a function doesreturn sort @fooor something likereturn map bar($_), sort @foo– even when the sorting is just a part of the function’s contract and not the operation of interest.That’s just ridiculous.
Also: first you say it would lead to non-backward compatible code, then you say it was left open for expansion. Which is it?
Re:I said "interesting", not "useful" (Score:2)
Re: (Score:1)
Ah. That is a more reasonable position.
I still don’t see the point. A superbly useful special semantic for the scalar context return of
sortwill never materialise. It’s been “open for expansion” for over a decade and will remain so for the next one, too.I’d rather rid the world of another special case, boring as that may be, and spare five people per year the surprise of tripping over this.
But eh.
List in scalar context?!? (Score:2)
So you think map and grep do return a list in scalar context? They don't. They return, in true Perl tradition, a list in list context, and they return "some useful value" in scalar context, which needn't even be related to that list. As grep and map in list context do not necessarily return the same number of items as they have arguments, it makes sense to make them return the count of items they wo