raku

Is there a fast parallel “for” loop in Perl 6?

我们两清 提交于 2020-06-25 09:37:13
问题 Given some code which does a bit of math/casting for each number from 1 to 500000, we have options: Simple for loop: for ^500000 -> $i { my $result = ($i ** 2).Str; } . In my unscientific benchmark, this takes 2.8 seconds. The most canonical parallel version does each bit of work in a Promise , then waits for the result. await do for ^500000 -> $i { start { my $result = ($i ** 2).Str; } } takes 19 seconds. This is slow! Creating a new promise must have too much overhead to be worthwhile for

What is the meaning of (Any) in Raku - specifically the ()?

吃可爱长大的小学妹 提交于 2020-06-13 18:47:19
问题 Here is an experiment with Raku: > my $x (Any) > my $y=1 1 > my @a=[1, 2] [1 2] > my %h=a=>'b' {a => b} > say "nil" unless $x nil I can see that [] indicates an array literal, {} a hash literal. I can also see that (Any) behaves like nil - returning false in the boolean context shown above. I find the (Any) interesting. The documentation tells me that Any is just one of the god classes in Raku. But what do the parenthesis () around Any tell me? 回答1: When you use the REPL, the result of the

What is the meaning of (Any) in Raku - specifically the ()?

邮差的信 提交于 2020-06-13 18:46:29
问题 Here is an experiment with Raku: > my $x (Any) > my $y=1 1 > my @a=[1, 2] [1 2] > my %h=a=>'b' {a => b} > say "nil" unless $x nil I can see that [] indicates an array literal, {} a hash literal. I can also see that (Any) behaves like nil - returning false in the boolean context shown above. I find the (Any) interesting. The documentation tells me that Any is just one of the god classes in Raku. But what do the parenthesis () around Any tell me? 回答1: When you use the REPL, the result of the

What could be the reason that `require` doesn't work in some places?

守給你的承諾、 提交于 2020-06-12 02:18:05
问题 Loading a module ( ABC ) with require works in one module of a distribution while it fails in another module of the distribution. What could be the reason that loading ABC with require fails in one place? require Name::ABC; my $new = Name::ABC.new(); # dies: You cannot create an instance of this type (ABC) perl6 -v This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03 implementing Perl 6.d. The the required module: App::DBBrowser::Subqueries App::DBBrowser::Union, line 80: OK

What could be the reason that `require` doesn't work in some places?

╄→尐↘猪︶ㄣ 提交于 2020-06-12 02:16:32
问题 Loading a module ( ABC ) with require works in one module of a distribution while it fails in another module of the distribution. What could be the reason that loading ABC with require fails in one place? require Name::ABC; my $new = Name::ABC.new(); # dies: You cannot create an instance of this type (ABC) perl6 -v This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03 implementing Perl 6.d. The the required module: App::DBBrowser::Subqueries App::DBBrowser::Union, line 80: OK

What could be the reason that `require` doesn't work in some places?

元气小坏坏 提交于 2020-06-12 02:15:43
问题 Loading a module ( ABC ) with require works in one module of a distribution while it fails in another module of the distribution. What could be the reason that loading ABC with require fails in one place? require Name::ABC; my $new = Name::ABC.new(); # dies: You cannot create an instance of this type (ABC) perl6 -v This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03 implementing Perl 6.d. The the required module: App::DBBrowser::Subqueries App::DBBrowser::Union, line 80: OK

Defining classes with several API versions together

孤者浪人 提交于 2020-05-29 02:37:09
问题 That's not apparently possible... role Versioned { method version () { return self.^api; } } class WithApi:ver<0.0.1>:auth<github:JJ>:api<0> does Versioned {} class WithApi:ver<0.0.1>:auth<github:JJ>:api<1> does Versioned {} say WithApi:api<0>.new.version; say WithApi:api<1>.new.version; This dies with ==SORRY!=== Error while compiling /home/jmerelo/progs/perl6/my-perl6-examples/api-versioned.p6 Redeclaration of symbol 'WithApi' at /home/jmerelo/progs/perl6/my-perl6-examples/api-versioned.p6

Signature can't be resolved when it's aliased to a constant

我只是一个虾纸丫 提交于 2020-05-14 19:11:02
问题 As a follow up to this question about using different APIs in a single program, Liz Mattijsen suggested to use constants. Now here's a different use case: let's try to create a multi that differentiates by API version, like this: class WithApi:ver<0.0.1>:auth<github:JJ>:api<1> {} my constant two = my class WithApi:ver<0.0.1>:auth<github:JJ>:api<2> {} multi sub get-api( WithApi $foo where .^api() == 1 ) { return "That's version 1"; } multi sub get-api( WithApi $foo where .^api() == 2 ) {

Signature can't be resolved when it's aliased to a constant

好久不见. 提交于 2020-05-14 19:07:32
问题 As a follow up to this question about using different APIs in a single program, Liz Mattijsen suggested to use constants. Now here's a different use case: let's try to create a multi that differentiates by API version, like this: class WithApi:ver<0.0.1>:auth<github:JJ>:api<1> {} my constant two = my class WithApi:ver<0.0.1>:auth<github:JJ>:api<2> {} multi sub get-api( WithApi $foo where .^api() == 1 ) { return "That's version 1"; } multi sub get-api( WithApi $foo where .^api() == 2 ) {

Signature restriction in roles in raku

你。 提交于 2020-05-14 17:47:07
问题 Maybe I'm missing something, but I'd like to know if there is a good reason why this code should compile role L { method do-l (Int, Int --> Int ) { ... } } class A does L { method do-l (Int $a, Real $b --> Str) { .Str ~ ": Did you expect Int?" with $a + $b } } my $a = A.new; say $a.do-l: 2, 3.323 This will output 5.323: Did you expect Int? I was curious if someone know a way for the compiler to at least throw some warning with the implemented signature of the role L . 回答1: throw some warning