我有一个特殊的函数,它接受一个列表,列表的每个成员必须满足多个要求.如何在perl6函数中设置它?
sub specialFunc(List $x) {};
(1) $x is a list # easy, List $x, but what about the following:
(2) each member of $x is numeric
(3) each member of $x is positive
(4) each member of $x is greater than 7
(5) each member of $x is odd number
(6) each member of $x is either the square or the cube of an even number plus 1;
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助 !!
lisprog
我试图匹配一个区分大小写或不区分大小写的字符串.有没有办法让.match方法将副词作为变量?
my $aString = "foo bar baz";
my @anArray = <OO AR AZ>;
my $anAdverb = :i;
my $firstCheck = ($aString.match(/$anAdverb "@anArray[0]" /)).Bool;
Run Code Online (Sandbox Code Playgroud)
$anAdverb在正则表达式内部使用不起作用.有解决方法吗?
我需要从同一个套接字或 $*IN 读取多个线程;然而,似乎有错误,因为每个人都试图从同一个来源读取(我认为)。解决此问题的最佳方法是什么?谢谢 !!
my $x = start { prompt("I am X: Enter x: "); }
my $y = start { prompt("I am Y: Enter y: "); }
await $x, $y;
say $x;
say $y;
Run Code Online (Sandbox Code Playgroud)
以下是错误:
I am X: Enter x: I am Y: Enter y: Tried to get the result of a broken Promise
in block <unit> at zz.pl line 4
Original exception:
Tried to read() from an IO handle outside its originating thread
in block at zz.pl line …Run Code Online (Sandbox Code Playgroud) 如果这个问题应该出现在更合适的论坛中,请指出我。谢谢。
我正在尝试升级到 Star Bundle 2022.02,但失败了。我觉得尝试调整源代码对我来说太麻烦了。解决办法是什么?
我下载了 tar 球并解压了它;然后跑了
./bin/rstar install
Run Code Online (Sandbox Code Playgroud)
错误是:
[2022-03-12T23:18:15] [INFO] Installing Raku in /home/lisprog/Perl6/rakudo-star-2022.02
[2022-03-12T23:18:15] [INFO] Starting build on MoarVM
[2022-03-12T23:18:15] [NOTIC] Using /home/lisprog/Perl6/rakudo-star-2022.02/tmp/tmp.qVxYSNmS0X as working directory
[2022-03-12T23:18:15] [NOTIC] Build log available at /home/lisprog/Perl6/rakudo-star-2022.02/tmp/tmp.819bVtG6xv
[2022-03-12T23:20:30] [INFO] Starting build on NQP
[2022-03-12T23:20:30] [NOTIC] Using /home/lisprog/Perl6/rakudo-star-2022.02/tmp/tmp.JQlrQlVRgO as working directory
cp: cannot stat '/home/lisprog/Perl6/rakudo-star-2022.02/src/nqp-2022.024/nqp-2022.024/.': No such file or directory
[2022-03-12T23:20:30] [ALERT] Build failed!
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用git和curl,但同样失败。
我正在尝试编写在promises中运行的3个echo服务器,但我想知道哪个承诺正在进行回显.有没有办法做到这一点?
no strict;
for 0 .. 2 -> $index {
@result[$index] = start {
$myID = $index;
say "======> $myID\n";
my $rsSocket = IO::Socket::INET.new:
localhost => 'localhost',
localport => 1234 + $index,
listen => 1;
while $rsSocket.accept -> $rsConnection {
say "Promise $myID accepted connection";
while $rsConnection.recv -> $stuff {
say "promise $myID Echoing $stuff";
$rsConnection.print($stuff);
}
$rsConnection.close;
}
}
}
await @result;
Run Code Online (Sandbox Code Playgroud)
echo服务器运行正常; 用"nc"测试;
在创建承诺之后,问题$myID就2出现了,并且我无法告诉哪个承诺正在进行当前的回显.它似乎$myID被所有的承诺所使用; 有没有办法创建特定于个人承诺的变量?
当使用相同字母名称但使用不同符号的变量时,似乎存在一些不一致的行为:
> my $a="foo";
foo
> my @a=1,2
[1 2]
> say $a
foo # this is what I have expected
> my $b = 1,2,3
(1 2 3)
> my @b = (0, $b.Slip)
[0 1] # I expect to get [0 1 2 3]; (0, |$b) not work either
> say $b
1 # I expect $b to be unchanged, (1,2,3), but it is now 1;
> say @a
[1 2]
> say @b
[0 1]
>
Run Code Online (Sandbox Code Playgroud)
我不确定为什么 …
我正在尝试做的是允许程序根据遇到的文本来定义字符类。但是,<[]>从字面上接受字符,并且以下产生错误:
my $all1Line = slurp "htmlFile";
my @a = ($all1Line ~~ m:g/ (\" || \') ~ $0 {} :my $marker = $0; http <-[ $marker ]>*? page <-[ $marker ]>*? /); # error: $marker is taken literally as $ m a r k e r
Run Code Online (Sandbox Code Playgroud)
我想匹配所有格式为“ https:// foo?page = 0?ssl = 1 ”或“ http ... page ...”的链接
非常感谢你!
我经常需要将数据从一种类型转换为另一种类型,然后进行比较。一些运算符会先转换为特定类型,这种转换可能会导致效率损失。例如,我可能有
my $a, $b = 0, "foo"; # initial value
$a = (3,4,5).Set; # re-assign value
$b = open "dataFile"; # re-assign value
if $a eq $b { say "okay"; } # convert to string
if $a == 5 { say "yes"; } # convert to number
if $a == $b {} # error, Cannot resolve caller Numeric(IO::Handle:D: );
Run Code Online (Sandbox Code Playgroud)
运算符“eq”和“==”将首先将数据转换为可消化的类型,这可能会减慢速度。如果无法提前知道要比较的数据,运算符“eqv”和“===”是否会跳过转换数据类型并提高效率(即,您完全不知道将要获得什么)?
我试图将 for 循环中的参数放入 FIXED 大小的数组中。这就是我一直在做的事情(我想使用一个包含 3 个元素的数组 @m):
for (1..19).rotor(3, :partial) -> @m { say @m; } # works, but I cannot specify size of @m
Run Code Online (Sandbox Code Playgroud)
但是,以下所有内容都给了我错误:
for (1..19).rotor(3, :partial) -> @m[0,1,2] { say @m; }
===SORRY!=== Error while compiling:
Variable '@m' is not declared
------> ).rotor(3, :partial) -> @m[0,1,2] { say ?@m; }
for (1..19).rotor(3 => -2) -> @m[0..2] { say @m; }
===SORRY!=== Error while compiling:
Variable '@m' is not declared
------> 1..19).rotor(3 => -2) -> @m[0..2] { …Run Code Online (Sandbox Code Playgroud) 我记得在大学时代,线程共享资源和内存。我不知道线程的 Raku 实现的细节,但是如果同时多个线程使用不同的参数调用同一个全局函数,它们会不会相互干扰,因为全局函数是所有线程共享的单个代码块线程?例如,这个例子没有显示干扰,但是一些复杂的代码呢?
sub add ($a, $b) { $a + $b };
for 1..100 { start { sleep 1.rand; say "I am $_, {add($_, 1000)}"; } };
Run Code Online (Sandbox Code Playgroud) raku ×6
perl6 ×5
parameters ×2
variables ×2
arrays ×1
build ×1
comparison ×1
destructure ×1
for-loop ×1
function ×1
identity ×1
match ×1
promise ×1
sigils ×1
signature ×1
user-defined ×1