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 {say $Line};'
> cimtrak.log.12-08-2016_06:07:39.zip
> cimtrak.log.06-08-2018_16:07:39.zip
> cimtrak.log.06-08-2018_17:07:39.zip
> cimtrak.log.07-08-2018_06:07:39.zip
> cimtrak.log.07-08-2018_16:07:39.zip

I see this is well solved, but here is Yet Another Way to do it:
ls | perl6 -e '.say for lines().sort: {
( (/ (\d\d)"-"(\d\d)"-"(\d\d\d\d)"_"(\d\d)":"(\d\d)":"(\d\d) / ?? 
"$2$0$1$3$4$5" !! ""), $_ )
}'


— 
Hope this helps,
Bruce Gray (Util of Perlmonks)

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 ":" and providing 
> the invocant *before* the colon:  say sort(<3 5 2 1>: {$^a <=> $^b})
> 
> On Sat, Jun 9, 2018 at 4:05 PM Brandon Allbery  > wrote:
> 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 
> "sort:" has an invocant to work with.
> 
> On Sat, Jun 9, 2018 at 4:02 PM Xin Cheng  > wrote:
> 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 1>.sort: {$^a <=> $^b}'  # it works.
> 
> But I don't know what the colon here mean, although I know it works.
> 
> If I write something like this,
> 
> p6 'say sort: {$^a <=> $^b} < 3 5 2 1> '  # It doesn't work.
> 
> But why? Why the colon works in one form, but not in another form? So I want 
> to know the meaning of the colon when it works.
> 
> Regards
> 
> Xin
> 
>> On Jun 9, 2018, at 3:01 PM, Brandon Allbery > > wrote:
>> 
>> 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 PM Xin Cheng > > wrote:
>> 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/:  , and it 
>> explains something like this:
>> 
>> Used as an argument separator just like infix , and marks the argument to 
>> its left as the invocant. That turns what would otherwise be a function call 
>> into a method call.
>> 
>> substr('abc': 1);   # same as 'abc'.substr(1) 
>> Infix : is only allowed after the first argument of a non-method call. In 
>> other positions, it's a syntax error.
>> 
>> 
>> How does the above explanation related to the case in hand @x .= sort: { ... 
>> }; ? Is sort an invocant? Or I miss something.
>> 
>> Regards
>> 
>> Xin
>> 
>> 
>> 
>>> On Jun 9, 2018, at 12:44 PM, Brandon Allbery >> > wrote:
>>> 
>>> 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 numbers. 
>>> The // replaces those with the following value (0), so they do something 
>>> sensible when sorted instead of producing warnings.
>>> 
>>> On Sat, Jun 9, 2018 at 11:40 AM Xin Cheng >> > wrote:
>>> 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, $minute // 0,
>>> $second // 0, $_);
>>> 
>>> Could somebody explain in some more words.? What does  // do? Why it sorts 
>>> the array?
>>> 
>>> Regards
>>> 
>>> Xin
>>> 
 On Jun 9, 2018, at 12:51 AM, Timo Paulssen >>> > wrote:
 
 That's unnecessarily long and complicated, here's how you can do it much
 easier:
 
 @x.sort: {
 my ($month, $day, $year, $hour, $minute, $second) = .comb(/\d+/);
 ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
 $second // 0, $_);
 }
 
 Trying it on some input data:
 
 cimtrak.log.06-08-2018_16:07:39.zip
 cimtrak.log.06-08-2018_17:07:39.zip
 cimtrak.log.07-08-2018_06:07:39.zip
 cimtrak.log.07-08-2018_16:07:39.zip
 cimtrak.log.12-08-2016_06:07:39.zip
 cookies
 asbestos
 fire engine
 perl6
 butterflies
 
 results in:
 
 asbestos

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, 2018 at 4:05 PM Brandon Allbery  wrote:

> 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
> "sort:" has an invocant to work with.
>
> On Sat, Jun 9, 2018 at 4:02 PM Xin Cheng  wrote:
>
>> 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 1>.sort: {$^a <=> $^b}'  # it works.
>>
>> But I don't know what the colon here mean, although I know it works.
>>
>> If I write something like this,
>>
>> p6 'say sort: {$^a <=> $^b} < 3 5 2 1> '  # It doesn't work.
>>
>> But why? Why the colon works in one form, but not in another form? So I
>> want to know the meaning of the colon when it works.
>>
>> Regards
>>
>> Xin
>>
>> On Jun 9, 2018, at 3:01 PM, Brandon Allbery  wrote:
>>
>> 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 PM Xin Cheng  wrote:
>>
>>> 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/: , and it explains something like this:
>>>
>>> Used as an argument separator just like infix , and marks the argument
>>> to its left as the invocant. That turns what would otherwise be a function
>>> call into a method call.
>>>
>>> substr('abc': 1);   # same as 'abc'.substr(1)
>>> Infix : is only allowed after the first argument of a non-method call.
>>> In other positions, it's a syntax error.
>>>
>>>
>>> How does the above explanation related to the case in hand @x .= sort: {
>>> ... }; ? Is sort an invocant? Or I miss something.
>>>
>>> Regards
>>>
>>> Xin
>>>
>>>
>>>
>>> On Jun 9, 2018, at 12:44 PM, Brandon Allbery 
>>> wrote:
>>>
>>> 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
>>> numbers. The // replaces those with the following value (0), so they do
>>> something sensible when sorted instead of producing warnings.
>>>
>>> On Sat, Jun 9, 2018 at 11:40 AM Xin Cheng  wrote:
>>>
 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, $minute // 0,
 $second // 0, $_);

 Could somebody explain in some more words.? What does  // do? Why it
 sorts the array?

 Regards

 Xin

 On Jun 9, 2018, at 12:51 AM, Timo Paulssen  wrote:

 That's unnecessarily long and complicated, here's how you can do it much
 easier:

 @x.sort: {
 my ($month, $day, $year, $hour, $minute, $second) =
 .comb(/\d+/);
 ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
 $second // 0, $_);
 }

 Trying it on some input data:

 cimtrak.log.06-08-2018_16:07:39.zip
 cimtrak.log.06-08-2018_17:07:39.zip
 cimtrak.log.07-08-2018_06:07:39.zip
 cimtrak.log.07-08-2018_16:07:39.zip
 cimtrak.log.12-08-2016_06:07:39.zip
 cookies
 asbestos
 fire engine
 perl6
 butterflies

 results in:

 asbestos
 butterflies
 cookies
 fire engine
 perl6
 cimtrak.log.12-08-2016_06:07:39.zip
 cimtrak.log.06-08-2018_16:07:39.zip
 cimtrak.log.06-08-2018_17:07:39.zip
 cimtrak.log.07-08-2018_06:07:39.zip
 cimtrak.log.07-08-2018_16:07:39.zip

 This is the schwartzian transform 

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
"sort:" has an invocant to work with.

On Sat, Jun 9, 2018 at 4:02 PM Xin Cheng  wrote:

> 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 1>.sort: {$^a <=> $^b}'  # it works.
>
> But I don't know what the colon here mean, although I know it works.
>
> If I write something like this,
>
> p6 'say sort: {$^a <=> $^b} < 3 5 2 1> '  # It doesn't work.
>
> But why? Why the colon works in one form, but not in another form? So I
> want to know the meaning of the colon when it works.
>
> Regards
>
> Xin
>
> On Jun 9, 2018, at 3:01 PM, Brandon Allbery  wrote:
>
> 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 PM Xin Cheng  wrote:
>
>> 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/: , and it explains something like this:
>>
>> Used as an argument separator just like infix , and marks the argument to
>> its left as the invocant. That turns what would otherwise be a function
>> call into a method call.
>>
>> substr('abc': 1);   # same as 'abc'.substr(1)
>> Infix : is only allowed after the first argument of a non-method call. In
>> other positions, it's a syntax error.
>>
>>
>> How does the above explanation related to the case in hand @x .= sort: {
>> ... }; ? Is sort an invocant? Or I miss something.
>>
>> Regards
>>
>> Xin
>>
>>
>>
>> On Jun 9, 2018, at 12:44 PM, Brandon Allbery  wrote:
>>
>> 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
>> numbers. The // replaces those with the following value (0), so they do
>> something sensible when sorted instead of producing warnings.
>>
>> On Sat, Jun 9, 2018 at 11:40 AM Xin Cheng  wrote:
>>
>>> 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, $minute // 0,
>>> $second // 0, $_);
>>>
>>> Could somebody explain in some more words.? What does  // do? Why it
>>> sorts the array?
>>>
>>> Regards
>>>
>>> Xin
>>>
>>> On Jun 9, 2018, at 12:51 AM, Timo Paulssen  wrote:
>>>
>>> That's unnecessarily long and complicated, here's how you can do it much
>>> easier:
>>>
>>> @x.sort: {
>>> my ($month, $day, $year, $hour, $minute, $second) = .comb(/\d+/);
>>> ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
>>> $second // 0, $_);
>>> }
>>>
>>> Trying it on some input data:
>>>
>>> cimtrak.log.06-08-2018_16:07:39.zip
>>> cimtrak.log.06-08-2018_17:07:39.zip
>>> cimtrak.log.07-08-2018_06:07:39.zip
>>> cimtrak.log.07-08-2018_16:07:39.zip
>>> cimtrak.log.12-08-2016_06:07:39.zip
>>> cookies
>>> asbestos
>>> fire engine
>>> perl6
>>> butterflies
>>>
>>> results in:
>>>
>>> asbestos
>>> butterflies
>>> cookies
>>> fire engine
>>> perl6
>>> cimtrak.log.12-08-2016_06:07:39.zip
>>> cimtrak.log.06-08-2018_16:07:39.zip
>>> cimtrak.log.06-08-2018_17:07:39.zip
>>> cimtrak.log.07-08-2018_06:07:39.zip
>>> cimtrak.log.07-08-2018_16:07:39.zip
>>>
>>> This is the schwartzian transform that was mentioned in another mail.
>>> why it wasn't actually shown, i have no clue :)
>>>
>>> Hope that helps
>>>   - Timo
>>>
>>>
>>>
>>
>> --
>> brandon s allbery kf8nh   sine nomine
>> associates
>> allber...@gmail.com
>> ballb...@sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>>
>>
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> 

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 1>.sort: {$^a <=> $^b}'  # it works.

But I don't know what the colon here mean, although I know it works.

If I write something like this,

p6 'say sort: {$^a <=> $^b} < 3 5 2 1> '  # It doesn't work.

But why? Why the colon works in one form, but not in another form? So I want to 
know the meaning of the colon when it works.

Regards

Xin

> On Jun 9, 2018, at 3:01 PM, Brandon Allbery  wrote:
> 
> 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 PM Xin Cheng  > wrote:
> 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/: 
>  , and it explains something like this:
> 
> Used as an argument separator just like infix , and marks the argument to its 
> left as the invocant. That turns what would otherwise be a function call into 
> a method call.
> 
> substr('abc': 1);   # same as 'abc'.substr(1) 
> Infix : is only allowed after the first argument of a non-method call. In 
> other positions, it's a syntax error.
> 
> 
> How does the above explanation related to the case in hand @x .= sort: { ... 
> }; ? Is sort an invocant? Or I miss something.
> 
> Regards
> 
> Xin
> 
> 
> 
>> On Jun 9, 2018, at 12:44 PM, Brandon Allbery > > wrote:
>> 
>> 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 numbers. 
>> The // replaces those with the following value (0), so they do something 
>> sensible when sorted instead of producing warnings.
>> 
>> On Sat, Jun 9, 2018 at 11:40 AM Xin Cheng > > wrote:
>> 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, $minute // 0,
>> $second // 0, $_);
>> 
>> Could somebody explain in some more words.? What does  // do? Why it sorts 
>> the array?
>> 
>> Regards
>> 
>> Xin
>> 
>>> On Jun 9, 2018, at 12:51 AM, Timo Paulssen >> > wrote:
>>> 
>>> That's unnecessarily long and complicated, here's how you can do it much
>>> easier:
>>> 
>>> @x.sort: {
>>> my ($month, $day, $year, $hour, $minute, $second) = .comb(/\d+/);
>>> ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
>>> $second // 0, $_);
>>> }
>>> 
>>> Trying it on some input data:
>>> 
>>> cimtrak.log.06-08-2018_16:07:39.zip
>>> cimtrak.log.06-08-2018_17:07:39.zip
>>> cimtrak.log.07-08-2018_06:07:39.zip
>>> cimtrak.log.07-08-2018_16:07:39.zip
>>> cimtrak.log.12-08-2016_06:07:39.zip
>>> cookies
>>> asbestos
>>> fire engine
>>> perl6
>>> butterflies
>>> 
>>> results in:
>>> 
>>> asbestos
>>> butterflies
>>> cookies
>>> fire engine
>>> perl6
>>> cimtrak.log.12-08-2016_06:07:39.zip
>>> cimtrak.log.06-08-2018_16:07:39.zip
>>> cimtrak.log.06-08-2018_17:07:39.zip
>>> cimtrak.log.07-08-2018_06:07:39.zip
>>> cimtrak.log.07-08-2018_16:07:39.zip
>>> 
>>> This is the schwartzian transform that was mentioned in another mail.
>>> why it wasn't actually shown, i have no clue :)
>>> 
>>> Hope that helps
>>>   - Timo
>> 
>> 
>> 
>> -- 
>> brandon s allbery kf8nh   sine nomine associates
>> allber...@gmail.com  
>>  ballb...@sinenomine.net 
>> unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net 
>> 
> 
> 
> -- 
> brandon s allbery kf8nh   sine nomine associates
> allber...@gmail.com   
> ballb...@sinenomine.net 
> unix, openafs, kerberos, infrastructure, xmonad

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 PM Xin Cheng  wrote:

> 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/: , and it explains something like this:
>
> Used as an argument separator just like infix , and marks the argument to
> its left as the invocant. That turns what would otherwise be a function
> call into a method call.
>
> substr('abc': 1);   # same as 'abc'.substr(1)
> Infix : is only allowed after the first argument of a non-method call. In
> other positions, it's a syntax error.
>
>
> How does the above explanation related to the case in hand @x .= sort: {
> ... }; ? Is sort an invocant? Or I miss something.
>
> Regards
>
> Xin
>
>
>
> On Jun 9, 2018, at 12:44 PM, Brandon Allbery  wrote:
>
> 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
> numbers. The // replaces those with the following value (0), so they do
> something sensible when sorted instead of producing warnings.
>
> On Sat, Jun 9, 2018 at 11:40 AM Xin Cheng  wrote:
>
>> 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, $minute // 0,
>> $second // 0, $_);
>>
>> Could somebody explain in some more words.? What does  // do? Why it
>> sorts the array?
>>
>> Regards
>>
>> Xin
>>
>> On Jun 9, 2018, at 12:51 AM, Timo Paulssen  wrote:
>>
>> That's unnecessarily long and complicated, here's how you can do it much
>> easier:
>>
>> @x.sort: {
>> my ($month, $day, $year, $hour, $minute, $second) = .comb(/\d+/);
>> ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
>> $second // 0, $_);
>> }
>>
>> Trying it on some input data:
>>
>> cimtrak.log.06-08-2018_16:07:39.zip
>> cimtrak.log.06-08-2018_17:07:39.zip
>> cimtrak.log.07-08-2018_06:07:39.zip
>> cimtrak.log.07-08-2018_16:07:39.zip
>> cimtrak.log.12-08-2016_06:07:39.zip
>> cookies
>> asbestos
>> fire engine
>> perl6
>> butterflies
>>
>> results in:
>>
>> asbestos
>> butterflies
>> cookies
>> fire engine
>> perl6
>> cimtrak.log.12-08-2016_06:07:39.zip
>> cimtrak.log.06-08-2018_16:07:39.zip
>> cimtrak.log.06-08-2018_17:07:39.zip
>> cimtrak.log.07-08-2018_06:07:39.zip
>> cimtrak.log.07-08-2018_16:07:39.zip
>>
>> This is the schwartzian transform that was mentioned in another mail.
>> why it wasn't actually shown, i have no clue :)
>>
>> Hope that helps
>>   - Timo
>>
>>
>>
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
>
>

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


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/: 
 , and it explains something like this:

Used as an argument separator just like infix , and marks the argument to its 
left as the invocant. That turns what would otherwise be a function call into a 
method call.

substr('abc': 1);   # same as 'abc'.substr(1) 
Infix : is only allowed after the first argument of a non-method call. In other 
positions, it's a syntax error.


How does the above explanation related to the case in hand @x .= sort: { ... }; 
? Is sort an invocant? Or I miss something.

Regards

Xin



> On Jun 9, 2018, at 12:44 PM, Brandon Allbery  wrote:
> 
> 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 numbers. 
> The // replaces those with the following value (0), so they do something 
> sensible when sorted instead of producing warnings.
> 
> On Sat, Jun 9, 2018 at 11:40 AM Xin Cheng  > wrote:
> 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, $minute // 0,
> $second // 0, $_);
> 
> Could somebody explain in some more words.? What does  // do? Why it sorts 
> the array?
> 
> Regards
> 
> Xin
> 
>> On Jun 9, 2018, at 12:51 AM, Timo Paulssen > > wrote:
>> 
>> That's unnecessarily long and complicated, here's how you can do it much
>> easier:
>> 
>> @x.sort: {
>> my ($month, $day, $year, $hour, $minute, $second) = .comb(/\d+/);
>> ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
>> $second // 0, $_);
>> }
>> 
>> Trying it on some input data:
>> 
>> cimtrak.log.06-08-2018_16:07:39.zip
>> cimtrak.log.06-08-2018_17:07:39.zip
>> cimtrak.log.07-08-2018_06:07:39.zip
>> cimtrak.log.07-08-2018_16:07:39.zip
>> cimtrak.log.12-08-2016_06:07:39.zip
>> cookies
>> asbestos
>> fire engine
>> perl6
>> butterflies
>> 
>> results in:
>> 
>> asbestos
>> butterflies
>> cookies
>> fire engine
>> perl6
>> cimtrak.log.12-08-2016_06:07:39.zip
>> cimtrak.log.06-08-2018_16:07:39.zip
>> cimtrak.log.06-08-2018_17:07:39.zip
>> cimtrak.log.07-08-2018_06:07:39.zip
>> cimtrak.log.07-08-2018_16:07:39.zip
>> 
>> This is the schwartzian transform that was mentioned in another mail.
>> why it wasn't actually shown, i have no clue :)
>> 
>> Hope that helps
>>   - Timo
> 
> 
> 
> -- 
> brandon s allbery kf8nh   sine nomine associates
> allber...@gmail.com   
> ballb...@sinenomine.net 
> unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net 
> 


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 numbers.
The // replaces those with the following value (0), so they do something
sensible when sorted instead of producing warnings.

On Sat, Jun 9, 2018 at 11:40 AM Xin Cheng  wrote:

> 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, $minute // 0,
> $second // 0, $_);
>
> Could somebody explain in some more words.? What does  // do? Why it sorts
> the array?
>
> Regards
>
> Xin
>
> On Jun 9, 2018, at 12:51 AM, Timo Paulssen  wrote:
>
> That's unnecessarily long and complicated, here's how you can do it much
> easier:
>
> @x.sort: {
> my ($month, $day, $year, $hour, $minute, $second) = .comb(/\d+/);
> ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
> $second // 0, $_);
> }
>
> Trying it on some input data:
>
> cimtrak.log.06-08-2018_16:07:39.zip
> cimtrak.log.06-08-2018_17:07:39.zip
> cimtrak.log.07-08-2018_06:07:39.zip
> cimtrak.log.07-08-2018_16:07:39.zip
> cimtrak.log.12-08-2016_06:07:39.zip
> cookies
> asbestos
> fire engine
> perl6
> butterflies
>
> results in:
>
> asbestos
> butterflies
> cookies
> fire engine
> perl6
> cimtrak.log.12-08-2016_06:07:39.zip
> cimtrak.log.06-08-2018_16:07:39.zip
> cimtrak.log.06-08-2018_17:07:39.zip
> cimtrak.log.07-08-2018_06:07:39.zip
> cimtrak.log.07-08-2018_16:07:39.zip
>
> This is the schwartzian transform that was mentioned in another mail.
> why it wasn't actually shown, i have no clue :)
>
> Hope that helps
>   - Timo
>
>
>

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


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 "// 0" is there in every field because if the input line doesn't
have the expected format, you'll get a bunch of warnings, because the
variables will contain undefined values, you can try it for yourself
with inputs like "anaconda", "beetle", "zebra".

The last part of the puzzle is how sort will sort lists of lists
(because it has now replaced every string with a list of the parts we've
supplied); By default, sort uses the earliest entry in the list that is
different, so it's very much like lexicographic sort.

Does that explain everything?
  - Timo


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, $minute // 0,
$second // 0, $_);

Could somebody explain in some more words.? What does  // do? Why it sorts the 
array?

Regards

Xin

> On Jun 9, 2018, at 12:51 AM, Timo Paulssen  wrote:
> 
> That's unnecessarily long and complicated, here's how you can do it much
> easier:
> 
> @x.sort: {
> my ($month, $day, $year, $hour, $minute, $second) = .comb(/\d+/);
> ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
> $second // 0, $_);
> }
> 
> Trying it on some input data:
> 
> cimtrak.log.06-08-2018_16:07:39.zip
> cimtrak.log.06-08-2018_17:07:39.zip
> cimtrak.log.07-08-2018_06:07:39.zip
> cimtrak.log.07-08-2018_16:07:39.zip
> cimtrak.log.12-08-2016_06:07:39.zip
> cookies
> asbestos
> fire engine
> perl6
> butterflies
> 
> results in:
> 
> asbestos
> butterflies
> cookies
> fire engine
> perl6
> cimtrak.log.12-08-2016_06:07:39.zip
> cimtrak.log.06-08-2018_16:07:39.zip
> cimtrak.log.06-08-2018_17:07:39.zip
> cimtrak.log.07-08-2018_06:07:39.zip
> cimtrak.log.07-08-2018_16:07:39.zip
> 
> This is the schwartzian transform that was mentioned in another mail.
> why it wasn't actually shown, i have no clue :)
> 
> Hope that helps
>   - Timo



[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 here.

The `has $.foo` attribute syntax is just a shorthand for writing `has $!foo; 
method foo { $!foo }`.
In other words, the compiler auto-generated an accessor method for you.

When you use `$.foo` syntax inside a method, it's a shorthand for `self.foo`; 
in other words, it's a
method call.

If you define a method with the same name as the attribute, then it signals to 
the compiler that you chose
to take care of accessor method yourself.

Also, to return a writeable container, you need to either use `return-rw` 
instead of plain `return` when
using explicit return, or apply the `is rw` trait to the method, when using 
implicit return:


method var1() is rw { return$!var }
method var2()   { return-rw $!var }

With that knowledge, you can see why the failing examples fail:

* EXAMPLE 3: You defined a method with the same name as attribute, so it'll 
function as the accessor. The body
 of that method is empty, so it returns `Nil` and hence the error 
about trying to assign to `Nil`
* EXAMPLE 4: Again, you defined your own accessor, but now you're also using 
`$.var` syntax inside, so the method
 infiniloops calling itself over and over. Hence the hang.
* EXAMPLE 5: You've used `return` instead of `return-rw`, so only a readonly 
value is returned instead of a
 writable container. Hence the error

> but shouldn't there be some type of prohibition/warning?

No, as it's perfectly fine to declare your own accessors. Of course, writing 
`has $.foo` instead of `has $!foo` is
pointless, in that case, but it serves as a hint to the programmer that it's a 
public attribute, so I don't think
warning about that is appropriate.


[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 here.

The `has $.foo` attribute syntax is just a shorthand for writing `has $!foo; 
method foo { $!foo }`.
In other words, the compiler auto-generated an accessor method for you.

When you use `$.foo` syntax inside a method, it's a shorthand for `self.foo`; 
in other words, it's a
method call.

If you define a method with the same name as the attribute, then it signals to 
the compiler that you chose
to take care of accessor method yourself.

Also, to return a writeable container, you need to either use `return-rw` 
instead of plain `return` when
using explicit return, or apply the `is rw` trait to the method, when using 
implicit return:


method var1() is rw { return$!var }
method var2()   { return-rw $!var }

With that knowledge, you can see why the failing examples fail:

* EXAMPLE 3: You defined a method with the same name as attribute, so it'll 
function as the accessor. The body
 of that method is empty, so it returns `Nil` and hence the error 
about trying to assign to `Nil`
* EXAMPLE 4: Again, you defined your own accessor, but now you're also using 
`$.var` syntax inside, so the method
 infiniloops calling itself over and over. Hence the hang.
* EXAMPLE 5: You've used `return` instead of `return-rw`, so only a readonly 
value is returned instead of a
 writable container. Hence the error

> but shouldn't there be some type of prohibition/warning?

No, as it's perfectly fine to declare your own accessors. Of course, writing 
`has $.foo` instead of `has $!foo` is
pointless, in that case, but it serves as a hint to the programmer that it's a 
public attribute, so I don't think
warning about that is appropriate.


[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
> >
> > The program:
> >
> > sub add-two-things ( $first, $second ) {
> > CATCH {
> > when X::Str::Numeric {
> > fail q/One of the arguments wasn't a number/
> > }
> > }
> >
> > for $first, $second {
> > warn "'$_' is not numeric" unless val($_) ~~ Numeric;
> > }
> >
> > return $first + $second;
> > }
> >
> > my @items = < 2 2 3 two nine ten 1 37 0 0 >;
> >
> > for @items -> $first, $second {
> > CONTROL {}
> > my $sum = add-two-things( $first, $second );
> >
> > put $sum.defined ??
> > "$first + $second = $sum" !!
> > "You can't add $first and $second";
> > }
> >


This is a dupe of https://github.com/MoarVM/MoarVM/issues/572 (also filed in 
Rakudo's repo: https://github.com/rakudo/rakudo/issues/1605 )

Closing this ticket in favour of those Issues.


[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
> >
> > The program:
> >
> > sub add-two-things ( $first, $second ) {
> > CATCH {
> > when X::Str::Numeric {
> > fail q/One of the arguments wasn't a number/
> > }
> > }
> >
> > for $first, $second {
> > warn "'$_' is not numeric" unless val($_) ~~ Numeric;
> > }
> >
> > return $first + $second;
> > }
> >
> > my @items = < 2 2 3 two nine ten 1 37 0 0 >;
> >
> > for @items -> $first, $second {
> > CONTROL {}
> > my $sum = add-two-things( $first, $second );
> >
> > put $sum.defined ??
> > "$first + $second = $sum" !!
> > "You can't add $first and $second";
> > }
> >


This is a dupe of https://github.com/MoarVM/MoarVM/issues/572 (also filed in 
Rakudo's repo: https://github.com/rakudo/rakudo/issues/1605 )

Closing this ticket in favour of those Issues.