rakudo

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

How do you access private methods or attributes from outside the type they belong to?

末鹿安然 提交于 2021-02-07 11:43:06
问题 In some rare cases where this would actually be acceptable, like in unit tests, you may want to get or set the value of a private attribute, or call a private method of a type where it shouldn't be possible. Is it really impossible? If not, how can you do it? 回答1: There are two ways you can access a private method of a type, and one way to get private attributes. All require meta-programming except for the first way to invoke private methods, whose explanation still involves meta-programming

Raku regex: Inconsistent longest token matching

若如初见. 提交于 2021-01-02 05:02:34
问题 Raku's regexes are expected to match longest token. And in fact, this behaviour is seen in this code: raku -e "'AA' ~~ m/A {say 1}|AA {say 2}/" # 2 However, when the text is in a variable, it does not seem to work in the same way: raku -e "my $a = 'A'; my $b = 'AA'; 'AA' ~~ m/$a {say 1}|$b {say 2}/" # 1 Why they work in a different way? Is there a way to use variables and still match the longest token? 回答1: There are two things at work here. The first is the meaning of "longest token". When

为什么现代的Perl默认情况下会避免使用UTF-8?

自古美人都是妖i 提交于 2020-08-05 20:45:18
问题: I wonder why most modern solutions built using Perl don't enable UTF-8 by default. 我想知道为什么大多数使用Perl构建的现代解决方案默认情况下都不启用 UTF-8 。 I understand there are many legacy problems for core Perl scripts, where it may break things. 我知道核心Perl脚本有很多遗留问题,可能会破坏事情。 But, from my point of view, in the 21 st century, big new projects (or projects with a big perspective) should make their software UTF-8 proof from scratch. 但是,从我的角度来看,在21 世纪 ,大型新项目(或具有大的方面讲项目)应该从头开始他们的软件UTF-8的证明。 Still I don't see it happening. 我仍然看不到它的发生。 For example, Moose enables strict and warnings, but not Unicode . 例如, Moose 启用严格和警告,但不启用

How to disable Perl 6 REPL creating .precomp

不想你离开。 提交于 2019-12-23 09:40:14
问题 Every time I run perl6 to enter the REPL mode, it creates a .precomp directory, which also slows down the appearance of the prompt. If the .precomp directory already exists, the prompt appears almost immediately, otherwise perl6 takes several seconds to create it. Is there a way to disable this feature? 回答1: Check if you have a PERL6LIB environment variable set, and if it contains . . I can produce exactly the behavior you're encountering if I set that. The solution is to clear that from your

How can I use Perl 5 modules from Perl 6?

亡梦爱人 提交于 2019-12-21 03:32:50
问题 Is the a way to use Perl 5 modules from CPAN from Rakudo Perl 6? For example, how can I use the venerable Perl 5 module, CGI, which hasn't been ported yet, in Perl 6. Update: And what this funky code from some early Perl 6 module: use CGI:from<perl5>; Is the :from<perl5> directive used to evoke some kind of a Perl 5 compatibility layer? Can't seem to find any documentation about it. 回答1: Use Inline::Perl5. The following example shows how to use the CPAN hosted Perl 5 module Text::Unidecode (

Why do I get 'divide by zero` errors when I try to run my script with Rakudo?

筅森魡賤 提交于 2019-12-12 11:47:35
问题 I just built Rakudo and Parrot so that I could play with it and get started on learning Perl 6. I downloaded the Perl 6 book and happily typed in the first demo program (the tennis tournament example). When I try to run the program, I get an error: Divide by zero current instr.: '' pc -1 ((unknown file):-1) I have my perl6 binary in the build directory. I added a scripts directory under the rakudo build directory: rakudo |- perl6 \- scripts |- perlbook_02.01 \- scores If I try to run even a

Concurrency, react-ing to more than one supply at a time

流过昼夜 提交于 2019-12-08 17:06:18
问题 Please consider the code below. Why is the output of this is "BABABA" and not "AAABAA" / "AABAAAB"? Shouldn't the two supplies run in parallel and the whenever fire immedeatly when there is an event in any of them? my $i = 0; my $supply1 = supply { loop { await Promise.in(3); done if $i++> 5; emit("B"); } }; my $supply2 = supply { loop { await Promise.in(1); done if $i++> 5; emit("A"); } }; react { #whenever Supply.merge($supply1, $supply2) -> $x { $x.print } whenever $supply1 -> $x { $x