Flycheck-raku module for MELPA

2020-05-27 Thread Xin Cheng
Hi

I am an emacs user, and I just installed the raku-mode for emacs. It is also 
advertised there is a flycheck-raku module on MELPA. But there is no such 
module. Instead, there is a flycheck-perl6 module. It seems the author would 
like people to switch from perl6-mode to raku-mode, from flycheck-perl6 to 
flycheck-raku. My guess is the author forget to upload the module to MELPA. 
Hopefully, the author is on the mailing list.

Regards

Xin




Re: IO ???

2018-06-16 Thread Xin Cheng
Thank you all for answering!

Regards

Ziping

> On Jun 16, 2018, at 1:13 PM, Elizabeth Mattijsen  wrote:
> 
>> On 16 Jun 2018, at 10:59, Xin Cheng  wrote:
>> I am wondering why the IO::Path class doesn't have a "close" method. After I 
>> read from a file by
>> 
>> $filename.IO.lines -> $line;
>> 
>> Am I supposed to close the file, or it is automatically closed for me after 
>> the reading?
> 
> If you read all of the lines from the file, then yes, the file will be closed 
> automatically for you.  This is *not* the case if you stop reading lines 
> after a while.  If you really want to be sure that the file will be closed in 
> that case, you will need to do that yourself by opening the file first, e.g. 
> like this:
> 
>with open($filename) -> $handle {
>LEAVE $handle.close;
>for $handle.lines -> $line {
>return if $line eq ‘foo’;  # will close
>}
>}
> 
> As soon as the scope of “with” is left, in whatever way, the file will be 
> closed by the LEAVE phaser.
> 
> 
> 
> Liz



Re: IO ???

2018-06-16 Thread Xin Cheng
I am wondering why the IO::Path class doesn't have a "close" method. After I 
read from a file by

$filename.IO.lines -> $line;

Am I supposed to close the file, or it is automatically closed for me after the 
reading?

I tried something like

$filename.IO.close;

It is a runtime error. It seems to me that no need to close. Do I understand 
right? If so, why?

Regards

Xin

> On Jun 3, 2018, at 1:05 PM, ToddAndMargo  wrote:
> 
>>> On Sun, Jun 3, 2018 at 1:01 PM ToddAndMargo >> > wrote:
>>>Hi All,
>>>I have a been looking around the docs pages and I am
>>>not finding a list of what the various IO functions do.
>>>I would like a list of IO.e does this and IO.d
>>>does that.
>>>Any such list exist?
>>>Many thanks,
>>>-T
> 
> On 06/03/2018 10:03 AM, Brandon Allbery wrote:
>> It's a bit subtle to track down, but the IO method gives you an IO::Path 
>> object. https://docs.perl6.org/type/IO::Path
> 
> I had found that, but I did not know what I was looking at.
> Thank you!



Re: How do I remove leading zeros?

2018-06-13 Thread Xin Cheng
Now we know the meaning of >> and <<. But what about <( and )> ? What do they 
mean here?

Thanks.
Xin

> On Jun 13, 2018, at 2:18 PM, Brad Gilbert  wrote:
> 
> On Wed, Jun 13, 2018 at 1:09 PM ToddAndMargo  > wrote:
>> 
>> On 06/13/2018 11:06 AM, ToddAndMargo wrote:
>>> On 06/13/2018 11:03 AM, ToddAndMargo wrote:
 On 06/13/2018 11:00 AM, Larry Wall wrote:
>> 
>>>$ p6 'my $x = "01.000.103.006.10"; $x ~~ s:g/«0+)>\d//; say "$x"'
>>>1.0.103.6.10
>> 
>> Hi Larry,
>> 
>> How did you get thee "«" character to appear?  And
>> what does it mean?
>> 
> 
> The way I type them is [compose] [<] [<], which is nice because their
> ASCII equivalent is <<
> 
> It means match a word boundary with the word being on the right side.
> 
>> say 'ABC DEF ' ~~ m:g/ << . /
>(「A」 「D」)
>> say 'ABC DEF ' ~~ m:g/ >> . /
>(「 」 「 」)



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  <mailto:allber...@gmail.com>> 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  <mailto:xinchen...@gmail.com>> 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 > <mailto:allber...@gmail.com>> 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 > <mailto:xinchen...@gmail.com>> 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/: <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 >> <mailto:allber...@gmail.com>> 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 >> <mailto:xinchen...@gmail.com>> 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 // 

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  <mailto:xinchen...@gmail.com>> 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/: 
> <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 > <mailto:allber...@gmail.com>> 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 > <mailto:xinchen...@gmail.com>> 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 >> <mailto:t...@wakelift.de>> 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-2

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/: 
<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  <mailto:xinchen...@gmail.com>> 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 > <mailto:t...@wakelift.de>> 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 <mailto:allber...@gmail.com>  
> ballb...@sinenomine.net <mailto:ballb...@sinenomine.net>
> unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net 
> <http://sinenomine.net/>


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



Re: How to print colorized text to the terminal

2018-06-04 Thread Xin Cheng
Thanks Bruce,

This is great, and It works as I expected.

I appreciate all the helps.

Regards

Xin

> On Jun 4, 2018, at 9:04 AM, Bruce Gray  wrote:
> 
> 
>> On Jun 3, 2018, at 7:41 PM, Xin Cheng  wrote:
>> 
>> I am trying to make a program to do grep with perl6 regular expression, and 
>> I would like to colorize the matched part to the terminal.
> —snip--
>>if $temp ~~ s/ (<$pattern>) /\\x1b\[31m$0\\x1b\[0m/ {say $temp}
> 
> —snip—
> 
> Change this:  s/ (<$pattern>) /\\x1b\[31m$0\\x1b\[0m/
> to this:  s/ (<$pattern>) /\x1b[31m$0\x1b[0m/
> and your example code will correctly highlight the pattern in the (terminal) 
> output.
> 
> The doubled backslash in your original code becomes a literal backslash; 
> “\\x1b” is 4 characters long, “\x1b” is 1 character long (the escape 
> character). Also, you would need to back-whack the `[` only on the left-hand 
> side of `s///` (the pattern, which uses Regex syntax), not on the right-hand 
> side (the replacement, which uses double-quoted string syntax).
> 
> If you do not want to use Terminal::ANSIColor, I recommend that you save 
> yourself some future confusion by isolating your escape sequences, like so:
> 
> constant $color_red = "\e[31m";
> constant $color_off = "\e[0m";
> 
> sub MAIN ( Str $pattern, Str $filename ) {
>for $filename.IO.lines -> $line  {
>my Str $temp = $line;
> 
># if no <> surrounding $pattern it becomes literal.
>if $temp ~~ s/ (<$pattern>) /$color_red$0$color_off/ { 
>say $temp;
>}
>}
> }
> 
> — 
> Hope this helps,
> Bruce Gray (Util of PerlMonks)
> 
> 



Re: How to print colorized text to the terminal

2018-06-03 Thread Xin Cheng
I just tried to use "put" in place of "say", and got the same result.

Thanks.

Ziping

> On Jun 3, 2018, at 8:44 PM, Brandon Allbery  wrote:
> 
> "say" uses the .gist method, which quotes the output for readability. You 
> probably want "put" instead.
> 
> On Sun, Jun 3, 2018 at 8:42 PM Xin Cheng  <mailto:xinchen...@gmail.com>> wrote:
> Hi,
> 
> I am trying to make a program to do grep with perl6 regular expression, and I 
> would like to colorize the matched part to the terminal. So the following is 
> what I wrote 
> 
> sub MAIN(Str $pattern,Str $filename){
> for $filename.IO.lines -> $line  {
> my Str $temp = $line;
> if $temp ~~ s/ (<$pattern>) /\\x1b\[31m$0\\x1b\[0m/ {say $temp}; # if 
> no <> surrounding $pattern it becomes literal.
> }
> }
> 
> And I named the program as grep6, and I tried it in zsh as
> 
> > grep6 'M.*N' =grep6
> 
> And I got,
> 
> sub \x1b[31mMAIN\x1b[0m(Str $pattern,Str $filename){
> 
> How do I turn the string into color?
> 
> Thanks!
> 
> Xin
> 
> 
> -- 
> brandon s allbery kf8nh   sine nomine associates
> allber...@gmail.com <mailto:allber...@gmail.com>  
> ballb...@sinenomine.net <mailto:ballb...@sinenomine.net>
> unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net 
> <http://sinenomine.net/>


How to print colorized text to the terminal

2018-06-03 Thread Xin Cheng
Hi,

I am trying to make a program to do grep with perl6 regular expression, and I 
would like to colorize the matched part to the terminal. So the following is 
what I wrote 

sub MAIN(Str $pattern,Str $filename){
for $filename.IO.lines -> $line  {
my Str $temp = $line;
if $temp ~~ s/ (<$pattern>) /\\x1b\[31m$0\\x1b\[0m/ {say $temp}; # if 
no <> surrounding $pattern it becomes literal.
}
}

And I named the program as grep6, and I tried it in zsh as

> grep6 'M.*N' =grep6

And I got,

sub \x1b[31mMAIN\x1b[0m(Str $pattern,Str $filename){

How do I turn the string into color?

Thanks!

Xin

Re: What is my sub?

2018-05-26 Thread Xin Cheng
Hi,

Why does anyone want to know the name of the sub inside the sub itself?

Is it more interesting to know the name of the calling sub?

Thanks!

Xin

> On May 26, 2018, at 2:32 PM, Larry Wall  wrote:
> 
> On Fri, May 25, 2018 at 07:23:45PM -0700, ToddAndMargo wrote:
> : Follow up:  based on Yary's wonderful advice, this is my keeper
> : on the subject:
> : 
> : 
> : 
> : perl6: what is the name of the subroutine you are currently in:
> : 
> : It is:
> :  &?ROUTINE.name
> :  callframe(0).code.name
> : 
> : $ p6 'sub flowers() { say "My subroutine name is <", &?ROUTINE.name,
> : ">" }; flowers;'
> : My subroutine name is 
> : 
> : 
> : $ p6 'sub flowers() { say "My subroutine name is <",
> : callframe(0).code.name, ">" }; flowers;'
> : My subroutine name is 
> 
> Important caveat: the callframe(0) will only work at the top level of
> the subroutine.  It doesn't work in an inner block, while &?ROUTINE.name
> does, since it locates the surrounding routine, however far out it needs
> to scan.  So, for example, if we add an extra set of braces:
> 
>$ p6 'sub flowers() { { say "My subroutine name is <", 
> callframe(0).code.name, ">" } }; flowers;'
>My subroutine name is <>
>$ p6 'sub flowers() { { say "My subroutine name is <", &?ROUTINE.name, ">" 
> } }; flowers;'
>My subroutine name is 
> 
> Larry