Larry Wall wrote:
On Sat, Jan 10, 2009 at 11:26:50PM +0300, Richard Hainsworth wrote:
More precisely, I dont understand the meaning of the ':' after '.sort'

It is turning the method call into a list operator, essentially.
It's not the so-called indirect object syntax, or it would be written:

    my @ranking = sort %players: { .value };

But the idea is related, and has a similar effect.  If you're familiar
with Haskell, it's a bit like the $ operator in working like an opening
parenthesis that needs no closing parenthesis.

things are becoming clearer. I tried out the alternatives:
my @ranking = %players.sort({.value});
has the same effect as as
my @ranking = %players.sort: {.value};
as you indicated.
Yet another way to write the sort is

    my @ranking = %placers.sort :{ .value };

my @ranking = %players.sort :{.value}; # white space before :, no ws after :

generates a syntax error with rakudo.
Is this a raduko bug, or am I not understanding your generic argument?
but in this case, the colon is introducing an adverb which modifies
the previous operator, which happens to be sort.  The difference
is that you can't continue the argument list after that, except
with more adverbs, whereas with the list operator form, the block
is merely the first argument:

    my @ranking = %placers.sort: { .value }, $some, $extra, $args;
(Not that sort would know what to do with extra args, but we're talking
about generic syntax...)


Reply via email to