raku

Raku regex: How to use capturing group inside lookaheads

落爺英雄遲暮 提交于 2021-02-20 06:32:30
问题 How can I use capturing groups inside lookahead assertion? This code: say "ab" ~~ m/(a) <?before (b) > /; returns: 「a」 0 => 「a」 But I was expecting to also capture 'b'. Is there a way to do so? I don't want to leave 'b' outside of the lookahead because I don't want 'b' to be part of the match. Is there a way to capture 'b' but still leave it outside of the match? NOTE: I tried to use Raku's capture markers, as in: say "ab" ~~ m/<((a))> (b) /; 「a」 0 => 「a」 1 => 「b」 But this does not seem to

Raku regex: How to use capturing group inside lookaheads

随声附和 提交于 2021-02-20 06:32:14
问题 How can I use capturing groups inside lookahead assertion? This code: say "ab" ~~ m/(a) <?before (b) > /; returns: 「a」 0 => 「a」 But I was expecting to also capture 'b'. Is there a way to do so? I don't want to leave 'b' outside of the lookahead because I don't want 'b' to be part of the match. Is there a way to capture 'b' but still leave it outside of the match? NOTE: I tried to use Raku's capture markers, as in: say "ab" ~~ m/<((a))> (b) /; 「a」 0 => 「a」 1 => 「b」 But this does not seem to

Raku regex: How to use capturing group inside lookaheads

一世执手 提交于 2021-02-20 06:29:33
问题 How can I use capturing groups inside lookahead assertion? This code: say "ab" ~~ m/(a) <?before (b) > /; returns: 「a」 0 => 「a」 But I was expecting to also capture 'b'. Is there a way to do so? I don't want to leave 'b' outside of the lookahead because I don't want 'b' to be part of the match. Is there a way to capture 'b' but still leave it outside of the match? NOTE: I tried to use Raku's capture markers, as in: say "ab" ~~ m/<((a))> (b) /; 「a」 0 => 「a」 1 => 「b」 But this does not seem to

What's the difference between $/ and $¢ in regex?

☆樱花仙子☆ 提交于 2021-02-16 15:49:46
问题 As the title indicates, what is the difference between $/ and $¢ ? They appear to always have the same value: my $text = "Hello world"; $text ~~ /(\w+) { say $/.raku } (\w+)/; $text ~~ /(\w+) { say $¢.raku } (\w+)/; Both result in Match objects with the same values. What's the logic in using one over the other? 回答1: The variable $/ refers to the most recent match while the variable $¢ refers to the most recent outermost match. In most basic regexes like the above, that may be one and the same

is export and binding in Perl 6

时间秒杀一切 提交于 2021-02-13 15:43:29
问题 Why isn't the value of a variable with := binding exported? $ cat myModule.pm6 our $a is export = 42; our $b is export := $a; $ cat program.p6 use myModule; say $a; say $b; $ perl6 program.p6 42 (Any) # Why? 回答1: An our -scoped variable is really just a lexical variable (like my ) that - instead of having a Scalar freshly created per scope - is initialized by being bound to a symbol of that name in the Stash of the current package. So effectively, this: our $foo; Is doing this: my $foo := $

perl6 grammar actions: unable to make anything if not using $/

我是研究僧i 提交于 2021-02-08 14:15:35
问题 I wrote a test program, and now it seems that if I don't use $/ in a method signature because I have to use .match inside the method, I can no long make anything. What did I do wrong? A further question is that if .match sets $/ , and $/ is read-only, then I cannot have $/ in the signature of a method that contains a .match statement, and I cannot have more than one .match inside the method because each .match will try to set the read-only $/ . This will be very awkward to program. Here is

perl6 grammar actions: unable to make anything if not using $/

你。 提交于 2021-02-08 14:15:02
问题 I wrote a test program, and now it seems that if I don't use $/ in a method signature because I have to use .match inside the method, I can no long make anything. What did I do wrong? A further question is that if .match sets $/ , and $/ is read-only, then I cannot have $/ in the signature of a method that contains a .match statement, and I cannot have more than one .match inside the method because each .match will try to set the read-only $/ . This will be very awkward to program. Here is

Raku .hyper() and .race() example not working

余生颓废 提交于 2021-02-08 13:39:08
问题 The following example code should accelerate the execution of a Raku program: for (1..4).race() { say "Doing $_"; sleep 1; } say now - INIT now; I remember, that it worked some time ago, but now I always end up with 4 seconds runtime. Also using .race() or adding parameters doesn't change anything. What does I have to do, to run 2 processes at the same time? 回答1: You should use race with the named argument batch and the statement prefix race. say race for (1..4).race(batch=>1) { say "Doing $_

Why doesn't Perl 6's try handle a non-zero exit in shell()?

心已入冬 提交于 2021-02-08 13:24:11
问题 This try catches the exception: try die X::AdHoc; say "Got to the end"; The output shows that the program continues: Got to the end If I attempt it with shell and a command that doesn't exit with 0, the try doesn't catch it: try shell('/usr/bin/false'); say "Got to the end"; The output doesn't look like an exception: The spawned command '/usr/bin/false' exited unsuccessfully (exit code: 1) in block <unit> at ... line ... What's going on that this makes it through the try? 回答1: The answer is

perl6 How to use junction inside regex interpolation?

血红的双手。 提交于 2021-02-08 13:14:41
问题 Sometimes I have a long list and I would like to check whether a string matches anything in the list. I am trying to interpolate a junction inside a regex. They are all errors. say "12345" ~~ m/ <{ (2,3,4).any }> / Cannot resolve caller MAKE_REGEX(Int, Bool, Bool, Int, PseudoStash); none of these signatures match: say "12345" ~~ m/ $( (2,3,4).any ) / This type cannot unbox to a native string: P6opaque, Junction Does this error message mean that junctions cannot be used inside regex