raku

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

Does changing Perl 6's $*OUT change standard output for child processes?

和自甴很熟 提交于 2019-12-08 15:30:12
问题 I was playing around with shell and how it acts when I change the standard filehandles in the calling program. Proc says: $in, $out and $err are the three standard streams of the to-be-launched program, and default to "-", which means they inherit the stream from the parent process. As far as I can tell, the external program doesn't use the same file handles: #!/Applications/Rakudo/bin/perl6 #`( make an external Perl 6 program the outputs to standard handles ) my $p6-name = 'in-out.p6'.IO;

print sth every second, and also sleep 10 seconds very 5 seconds using react … whenever in Perl 6?

♀尐吖头ヾ 提交于 2019-12-08 15:17:07
问题 I want to print the current time every second, and also want to sleep 10 seconds very 5 seconds: react { whenever Supply.interval(1) { say DateTime.now.posix; } whenever Supply.interval(5) { sleep 10; say 'Sleep Done'; } whenever signal(SIGINT) { say "Done."; done; } } the output is not what i wanted: 1542371045 Sleep Done 1542371055 Sleep Done 1542371065 Sleep Done 1542371075 Done. ... what i want is this: 1542371045 1542371046 1542371047 1542371048 1542371049 Sleep Done 1542371059

How to define variable names dynamically in Perl 6?

拈花ヽ惹草 提交于 2019-12-07 10:34:52
问题 I have a name which I'd like to give to a variable, in another string variable: my $name = '$a'; or simply my $name = 'a'; How to make the variable and to use it? I mean something like this (but it doesn't work): my $name = '$a'; my {$name} = 1; # Doesn't work say $a; # should be 1 A more general case. I have a list of variable names, say my @names = '$aa' ... '$cc'; How to declare and use the variable, whose name will be e.g. @names[2] ? 回答1: According to documentation the lexical pad

Not able to serve jupyter notebooks in binder

你离开我真会死。 提交于 2019-12-07 08:23:41
问题 Binder project looks promising. It helps in executing notebooks in a github repository by building an executable container. I am trying to build an executable container in binder with the following Dockerfile that has Perl 6 and Python 3 kernels: FROM sumdoc/perl-6 ENV NB_USER jovyan ENV NB_UID 1000 ENV HOME /home/${NB_USER} RUN adduser --disabled-password \ --gecos "Default user" \ --uid ${NB_UID} \ ${NB_USER} RUN apt-get update \ && apt-get install -y build-essential \ git wget libzmq3-dev

perl6 'do(file)' equivalent

落花浮王杯 提交于 2019-12-07 05:46:28
问题 In perl5 I used to 'do (file)' for configuration files like this: ---script.pl start --- our @conf = (); do '/path/some_conf_file'; ... foreach $item (@conf) { $item->{rules} ... ... ---script.pl end --- ---/path/some_conf_file start --- # arbitrary code to 'fill' @conf @conf = ( {name => 'gateway', rules => [ {verdict => 'allow', srcnet => 'gw', dstnet => 'lan2'} ] }, {name => 'lan <-> lan2', rules => [ {srcnet => 'lan', dstnet => 'lan2', verdict => 'allow', dstip => '192.168.5.0/24'} ] }, )

Find last Friday’s Date in Perl 6?

不羁的心 提交于 2019-12-07 04:46:45
问题 I want to generate a sequence that ends last Friday from Monday to Thursday, and the Friday of the previous week if the sequence starts on Saturday and Sunday. That is, assuming that today is 2018-05-09 , then last Friday is 2018-05-04 , If today is 2018-05-12 , then last Friday is also 2018-05-04 . So I write: (Date.today, *.earlier(:1day) ... ( *.day-of-week==5 && *.week[1]+1==Date.today.week[1] )).tail # Output: 2018-05-06 But the result is 2018-05-06 instead of 2018-05-04 . Then I used a

How can I discover all the roles a Perl 6 type does?

耗尽温柔 提交于 2019-12-06 20:24:51
问题 With .does I can check if a type has the role I already know. I'd like to get the list of roles. Inheritance has .^mro but I didn't see anything like that for roles in the meta model stuff. Along with that, given a "type", how can I tell if it was defined as a class or a role? 回答1: .^roles say Rat.^roles; # ((Rational[Int,Int]) (Real) (Numeric)) By default it includes every role, including roles brought in by other roles. To only get the first level use :!transitive Rat.^roles(:!transitive);

how do I create a stand-alone executable with perl 6?

穿精又带淫゛_ 提交于 2019-12-06 20:18:59
问题 The OLD Perl 6 faq said: "Rakudo, a Perl 6 compiler based on Parrot, allows compilation to bytecode, and a small wrapper exists that can pack up a bytecode file and parrot into a single executable." So, it was possible to create a stand-alone executable, but I can not find any docs explaining how to go about this, or if it's still possible. So, I turn to you. What is the appropriate set of incantations required to convert Perl 6 code into a stand-alone executable that will work on a system

Not able to serve jupyter notebooks in binder

泪湿孤枕 提交于 2019-12-05 19:11:57
Binder project looks promising. It helps in executing notebooks in a github repository by building an executable container. I am trying to build an executable container in binder with the following Dockerfile that has Perl 6 and Python 3 kernels: FROM sumdoc/perl-6 ENV NB_USER jovyan ENV NB_UID 1000 ENV HOME /home/${NB_USER} RUN adduser --disabled-password \ --gecos "Default user" \ --uid ${NB_UID} \ ${NB_USER} RUN apt-get update \ && apt-get install -y build-essential \ git wget libzmq3-dev ca-certificates python3-pip \ && rm -rf /var/lib/apt/lists/* && pip3 install jupyter notebook --no