in reply to Perversity of sorts

Think of built-in functions as subs with prototypes on steroids (whether you parse that as "(subs with prototypes) on steroids" or "subs with (prototypes on steroids)", either one is correct).

In this case, Perl is desperately trying to come up with a way to parse "sort do_nothing( @in )" in such a way as to match one of the two allowable formats. And it's getting it wrong. The bias seems to be for the "sort BLOCK EXPR" format over the "sort EXPR" format. Which largely makes sense from the abstract - "sort BLOCK EXPR" could be a subset of "sort EXPR", so we need to provide that bias.

Once we've gone down that road, do_nothing is being passed no arguments, returning an empty array in scalar context results in "0", and we end up having a block that always returns 0, and thus the input to sort is passed back out, unchanged.

With whitespace being significant in perl 6, that ambiguity goes away (to be substituted by whitespace being significant, unlike pretty much every other language).

Replies are listed 'Best First'.
Re^2: Perversity of sorts
by wolv (Pilgrim) on Apr 05, 2005 at 06:42 UTC
    my @results = @foo.sort(&comparator); my @results = @foo.sort:{ $^a <=> $^b };
    What whitespace? :)