raku

How to kill a thread, stop a promise execution in Raku

房东的猫 提交于 2021-01-27 04:25:51
问题 I am looking for a wait to stop (send an exception) to a running promise on SIGINT . The examples given in the doc exit the whole process and not just one worker. Does someone know how to "kill", "unschedule", "stop" a running thread ? This is for a p6-jupyter-kernel issue or this REPL issue. Current solution is restarting the repl but not killing the blocked thread await Promise.anyof( start { ENTER $running = True; LEAVE $running = False; CATCH { say $_; reset; } $output := self.repl-eval(

How to kill a thread, stop a promise execution in Raku

瘦欲@ 提交于 2021-01-27 04:24:30
问题 I am looking for a wait to stop (send an exception) to a running promise on SIGINT . The examples given in the doc exit the whole process and not just one worker. Does someone know how to "kill", "unschedule", "stop" a running thread ? This is for a p6-jupyter-kernel issue or this REPL issue. Current solution is restarting the repl but not killing the blocked thread await Promise.anyof( start { ENTER $running = True; LEAVE $running = False; CATCH { say $_; reset; } $output := self.repl-eval(

How to find number of matches to regexp in perl6?

妖精的绣舞 提交于 2021-01-27 04:11:32
问题 In Perl 5 we can write my @things = $text =~ /thing/g; And $things in scalar context is number of non-overlapping occurrences of substring thing in string $text . How to do this in Perl 6? 回答1: You can do it like this: my $text = 'thingthingthing' my @things = $text ~~ m:g/thing/; say +@things; # 3 ~~ matches the left side against the right side, m:g makes the test return a List[Match] containing all the results. 回答2: I found solution on RosettaCode . http://rosettacode.org/wiki/Count

How to find number of matches to regexp in perl6?

六眼飞鱼酱① 提交于 2021-01-27 04:10:44
问题 In Perl 5 we can write my @things = $text =~ /thing/g; And $things in scalar context is number of non-overlapping occurrences of substring thing in string $text . How to do this in Perl 6? 回答1: You can do it like this: my $text = 'thingthingthing' my @things = $text ~~ m:g/thing/; say +@things; # 3 ~~ matches the left side against the right side, m:g makes the test return a List[Match] containing all the results. 回答2: I found solution on RosettaCode . http://rosettacode.org/wiki/Count

How to find number of matches to regexp in perl6?

不羁的心 提交于 2021-01-27 04:10:07
问题 In Perl 5 we can write my @things = $text =~ /thing/g; And $things in scalar context is number of non-overlapping occurrences of substring thing in string $text . How to do this in Perl 6? 回答1: You can do it like this: my $text = 'thingthingthing' my @things = $text ~~ m:g/thing/; say +@things; # 3 ~~ matches the left side against the right side, m:g makes the test return a List[Match] containing all the results. 回答2: I found solution on RosettaCode . http://rosettacode.org/wiki/Count

Content checking some, not all, class attributes

纵然是瞬间 提交于 2021-01-27 03:57:55
问题 I have a class with attributes. I want to check whether some but not all are defined. So: class A { has $.a is rw; has $.b is rw; has $.c is rw; has $.d is rw; method delete { ... } } my A $x .= new(:a<hi>, :d<good>); ## later $x.b = 'there'; ## code in which $x.c may or may not be defined. ## now I want to check if the attributes a, b, and c are defined, without ## needing to know about d my Bool $taint = False; for <a b c> { $taint &&= $x.$_.defined } This will cause errors because an

Content checking some, not all, class attributes

百般思念 提交于 2021-01-27 03:54:21
问题 I have a class with attributes. I want to check whether some but not all are defined. So: class A { has $.a is rw; has $.b is rw; has $.c is rw; has $.d is rw; method delete { ... } } my A $x .= new(:a<hi>, :d<good>); ## later $x.b = 'there'; ## code in which $x.c may or may not be defined. ## now I want to check if the attributes a, b, and c are defined, without ## needing to know about d my Bool $taint = False; for <a b c> { $taint &&= $x.$_.defined } This will cause errors because an

Extracting JSON from a Raku HTTP client request

喜欢而已 提交于 2021-01-26 09:25:22
问题 I'm having trouble understanding what is wrong with this Raku code. I want to fetch JSON from a website, and print out a field from each item in an array within the JSON (in this case the titles of latest topics from any Discourse forum). This is code that I expected to work, but it failed: use HTTP::UserAgent; use JSON::Tiny; my $client = HTTP::UserAgent.new; $client.timeout = 10; my $url = 'https://meta.discourse.org/latest.json'; my $resp = $client.get($url); my %data = from-json($resp

Extracting JSON from a Raku HTTP client request

≯℡__Kan透↙ 提交于 2021-01-26 09:24:49
问题 I'm having trouble understanding what is wrong with this Raku code. I want to fetch JSON from a website, and print out a field from each item in an array within the JSON (in this case the titles of latest topics from any Discourse forum). This is code that I expected to work, but it failed: use HTTP::UserAgent; use JSON::Tiny; my $client = HTTP::UserAgent.new; $client.timeout = 10; my $url = 'https://meta.discourse.org/latest.json'; my $resp = $client.get($url); my %data = from-json($resp

Returning a 'raw' scalar container from AT-POS method (rather than a Proxy instance) in a class that 'does' Positional?

南笙酒味 提交于 2021-01-26 07:56:42
问题 I'm attempting to implement a class that 'does' Positional that also allows me to update its values by assigning to the result returned by the AT-POS method. Eventually, I was able to concoct the following class that works as intended: class Test does Positional { has $.slot_1 is rw = 12; has $.slot_2 is rw = 24; method AT-POS(\position) { my $t = self; return-rw Proxy.new: FETCH => method () { position % 2 ?? $t.slot_1 !! $t.slot_2 }, STORE => method ($v) { if position % 2 { $t.slot_1 = $v }