Re: need sort help

2018-06-09 Thread Bruce Gray
> On Jun 9, 2018, at 12:42 AM, ToddAndMargo wrote: —snip-- > Yippee!! Thank you! > > $ ls | perl6 -e 'my @x=lines(); for @x.sort: {my ($month, $day, $year, > $hour, $minute, $second) = .comb(/\d+/);($year // 0, $month // 0, $day // 0, > $hour // 0, $minute // 0,$second // 0, $_);} -> $Line

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 Brandon Allbery
The colon only works on a method call. In "say sort:" it's not used as a method, it's used as a sub; the colon causes it to try to reinterpret as a method call, then it can't find an invocant for the method to operate on. In "@x .= sort:", the ".=" forces a method call with @x as invocant; then

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

Re: need sort help

2018-06-09 Thread Xin Cheng
This is very interesting. But I wonder how it works. I can understand the first line my ($month, $day, $year, $hour, $minute, $second) = .comb(/\d+/); Which extract the variables from $_. What is the second line doing, it is very concise. ($year // 0, $month // 0, $day // 0, $hour // 0,

[perl #133246] Possible bug in Perl 6 OO

2018-06-09 Thread Zoffix Znet via RT
On Sat, 09 Jun 2018 05:33:04 -0700, c...@zoffix.com wrote: > when > using implicit return: > > > method var1() is rw { return$!var } > method var2() { return-rw $!var } Correction, that should be: method var1() is rw { $!var } method var2() { return-rw $!var }

[perl #133246] Possible bug in Perl 6 OO

2018-06-09 Thread Zoffix Znet via RT
On Sat, 09 Jun 2018 05:33:04 -0700, c...@zoffix.com wrote: > when > using implicit return: > > > method var1() is rw { return$!var } > method var2() { return-rw $!var } Correction, that should be: method var1() is rw { $!var } method var2() { return-rw $!var }

[perl #133246] Possible bug in Perl 6 OO

2018-06-09 Thread Zoffix Znet via RT
On Mon, 04 Jun 2018 07:31:40 -0700, richard.hogab...@gmail.com wrote: > Attached is an executable file that demos a possible Perl 6 OO bug if > attributes and method names are the same.  This includes some compile > time errors and an infinite loop. > Thanks for the report, but there's no bug

[perl #133246] Possible bug in Perl 6 OO

2018-06-09 Thread Zoffix Znet via RT
On Mon, 04 Jun 2018 07:31:40 -0700, richard.hogab...@gmail.com wrote: > Attached is an executable file that demos a possible Perl 6 OO bug if > attributes and method names are the same.  This includes some compile > time errors and an infinite loop. > Thanks for the report, but there's no bug

[perl #133268] MoarVM with empty CONTROL {}

2018-06-09 Thread Zoffix Znet via RT
On Fri, 08 Jun 2018 15:24:32 -0700, alex.jakime...@gmail.com wrote: > Golf: > > CONTROL {}; warn 42 > > On 2018-06-08 15:11:08, comdog wrote: > > While running this program I get a MoarVM panic: > > > > 2 + 2 = 4 > > 'two' is not numeric > > MoarVM panic: Trying to unwind over wrong handler > >

[perl #133268] MoarVM with empty CONTROL {}

2018-06-09 Thread Zoffix Znet via RT
On Fri, 08 Jun 2018 15:24:32 -0700, alex.jakime...@gmail.com wrote: > Golf: > > CONTROL {}; warn 42 > > On 2018-06-08 15:11:08, comdog wrote: > > While running this program I get a MoarVM panic: > > > > 2 + 2 = 4 > > 'two' is not numeric > > MoarVM panic: Trying to unwind over wrong handler > >