Re: need sort help

2018-06-09 Thread Xin Cheng
Got it, thanks. Xin > On Jun 9, 2018, at 4:07 PM, Brandon Allbery wrote: > > And in the others, you've provided an explicit invocant with " some kind>.sort", so again it knows it's a method call and has an invocant > already. > > A sub can be forced to be a method call instead by using ":"

Re: need sort help

2018-06-09 Thread Brandon Allbery
And in the others, you've provided an explicit invocant with ".sort", so again it knows it's a method call and has an invocant already. A sub can be forced to be a method call instead by using ":" and providing the invocant *before* the colon: say sort(<3 5 2 1>: {$^a <=> $^b}) On Sat, Jun 9,

Re: need sort help

2018-06-09 Thread Xin Cheng
Thanks. But I am actually confused by the use of colon in Sort: { ... } What does it mean in the above statement? I have done several experiments like: p6 'say sort({$^a <=> $^b}, < 3 5 2 1>)'# (1 2 3 5) p6 'say <3 5 2 1>.sort({$^a <=> $^b})' # it works. p6 'say <3 5 2

Re: need sort help

2018-06-09 Thread Brandon Allbery
The ".=" operator means call the method on the right, with the thing on the left as invocant, and assign the result back to the thing on the left. So @x .= sort: ... is the same as @x = @x.sort(...) So you're being confused by the syntactic "magic" of ".=". On Sat, Jun 9, 2018 at 2:58

Re: need sort help

2018-06-09 Thread Xin Cheng
I got the point for //. Another question is about calling the method sort with a code block. I can understand @x .= sort({ ... }); But I don't quite understand why this form also works. @x .= sort: { ... }; I look into the documentation for infix ":", https://docs.perl6.org/routine/:

Re: need sort help

2018-06-09 Thread Brandon Allbery
More precisely, at that point you have a bunch of numbers, but possibly not as many as expected if some of the components weren't numeric (or all of them, as when there are files present that aren't the expected logs). Which means some or all of those variables will be undefined instead of

Re: need sort help

2018-06-09 Thread Timo Paulssen
The magic trick is that the last line in the code block is the return value. when you pass a function that takes a single argument (in this case just the $_) to sort, it will call your function for every element in the input array and use the result of that function to sort the elements by. The