% raku\nWelcome to Rakudo\xe2\x84\xa2 v2023.08.\nImplementing the Raku\xc2\xae Programming Language v6.d.\nBuilt on MoarVM version 2023.08.\n\nTo exit type 'exit' or '^D'\n[0] > say so 1..0;\nTrue\nRun Code Online (Sandbox Code Playgroud)\nRange如果空值是False,但任何范围都是,这将很有用True。\n这是一个错误还是一个功能?
我正在尝试在OS X 10.6上安装Rakudo Star,并且我已经达到了令人沮丧的地步,我的构建失败了,我不知道如何处理.这里有没有人知道这个过去的方法?(我正在尝试将其设置为编写一些本地perl6程序,所以我不确定规则是否在服务器故障或堆栈溢出时需要这个,请根据需要打我)
我已经下载了提供的发行版并运行了
make VERSION=2010.07
要在文件夹中成功创建实际分发
rakudo-star-2010.07
对于任何感兴趣的人,我需要获取gnu find的端口版本(安装到/ opt/local/bin/gfind),然后将我的常规find替换为gfind.OS X发现缺少-printf选项.
顺便说一句,按照我的说法,我
$ cd rakudo-star-2010.07 $ perl Configure.pl --gen-parrot
这突然间有一段时间,但后来保释如下
/Users/alanstorm/Downloads/rakudo-star-7652a0b/rakudo-star-2010.07/install/src/parrot/2.6.0/pmc/timer.dump /Users/alanstorm/Downloads/rakudo-star-7652a0b/rakudo-star-2010.07/install/src/parrot/2.6.0/pmc/undef.dump /Users/alanstorm/Downloads/rakudo-star-7652a0b/rakudo-star-2010.07/install/src/parrot/2.6.0/pmc/unmanagedstruct.dump /Users/alanstorm/Downloads/rakudo-star-7652a0b/rakudo-star-2010.07/install/src/parrot/2.6.0/vtable.dump Finished install_dev_files.pl Reading configuration information from install/bin/parrot_config ... ===SORRY!=== Parrot revision r48225 required (currently r0) To automatically build the version of Parrot that came with this distribution (), try re-running Configure.pl with the '--gen-parrot' option. Or, use the '--parrot-config' option to explicitly specify the location of parrot_config to be used to build …
#!perl6
use v6;
my $longest = 3;
my @list = <a b c d e f>;
for @list -> $element is rw {
$element = sprintf "%*.*s", $longest, $longest, $element;
$element.say;
}
Run Code Online (Sandbox Code Playgroud)
这有效.但在第二和第三,我得到一个错误信息.我怎么能让他们工作?
#!perl6
use v6;
my $longest = 3;
my @list = <a b c d e f>;
for @list <-> $element {
$element = sprintf "%*.*s", $longest, $longest, $element;
$element.say;
}
# ===SORRY!===
# Missing block at line 11, near ""
Run Code Online (Sandbox Code Playgroud)
.
#!perl6
use v6;
my $longest = …Run Code Online (Sandbox Code Playgroud) 在Perl 5中,我可以说
my $meth = 'halt_and_catch_fire';
my $result = $obj->$meth();
Run Code Online (Sandbox Code Playgroud)
这对于迭代方法名称列表来执行操作非常方便.我已经设法搞清楚在Perl 6中我不能只说
my $result = $obj.$meth();
Run Code Online (Sandbox Code Playgroud)
有一件事做的工作
my $result = $obj.^can($meth)[0]($obj);
Run Code Online (Sandbox Code Playgroud)
但这似乎完全可怕.我该怎么办呢?
我正在与Laurent Rosenfeld一起阅读Think Perl 6, 最近与Allen B. Downey一起读这本书非常不错。
它的.tex文件在github 此处提供。
为此,我们必须对上述存储库中包含的所有.tex文件进行批处理。为此,我们必须转换乳胶代码:
\begin{verbatim}
say 42 == 42; # True
say 42 == 42.0; # True
say 42 === 42; # True
say 42 === 42.0; # False
\end{verbatim}
\begin{verbatim}
$x eq $y # $x is string-wise equal to $y
$x ne $y # $x is string-wise not equal to $y
$x gt $y # $x is greater than $y (alphabetically after) …Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的测试模块./mods/My/Module.pm6:
unit module My::Module;
use v6;
sub hello () is export {
say "Hello";
}
Run Code Online (Sandbox Code Playgroud)
然后,我有一个测试脚本./p.p6:
#! /usr/bin/env perl6
use v6;
use My::Module;
My::Module::hello();
Run Code Online (Sandbox Code Playgroud)
然后我设置PERL6LIB包含该文件夹./mods,然后运行脚本:
$ ./p.p6
Could not find symbol '&hello'
in block <unit> at ./p.p6 line 7
Run Code Online (Sandbox Code Playgroud)
但是,如果我替换My::Module::hello()脚本中的行,hello()它可以正常工作.我在这里错过了什么?
我有一个命令,期望从管道输入.例如,考虑一下着名的cat命令:
$ echo Hello | cat
Hello
Run Code Online (Sandbox Code Playgroud)
假设我在Perl 6程序中有一个字符串,我想管道输入命令:
use v6;
my $input = 'Hello'; # This is the string I want to pipe to the command.
my $proc = run 'cat', :in($input);
Run Code Online (Sandbox Code Playgroud)
这不起作用(我没有输出).我可以通过调用bash和解决这个问题echo:
my $proc = run 'bash', '-c', "echo $input | cat";
Run Code Online (Sandbox Code Playgroud)
但是,有没有一种方法,我可以做到这一点,但不运行bash和echo?
在Perl5中,我可以简单地做my $pid = open my $fh, '|-', 'cat';,然后print $fh $str.
我想删除a的任何元素SetHash,以便返回其值:
my SetHash $a;
$a<m n k> = 1..*;
my $elem = $a.mymethod;
say $elem; # n
say $a; # SetHash(m k)
Run Code Online (Sandbox Code Playgroud)
我可以分两步完成,如下所示.有没有更好的办法?
my $elem = $a.pick;
$a{$elem}--;
Run Code Online (Sandbox Code Playgroud)
顺便说一下,是否有更多惯用的方法可以添加几个元素SetHash?
以下是否更好?
my SetHash $a;
$a{$_}++ for <m n k>;
Run Code Online (Sandbox Code Playgroud)
要么
my SetHash $a;
$a<m n k> X= True;
Run Code Online (Sandbox Code Playgroud) This file will be foo.pm6:
sub bar { "quux" }
say "Loaded";
Run Code Online (Sandbox Code Playgroud)
And this one requirer.p6:
require "foo.pm6";
say bar;
Run Code Online (Sandbox Code Playgroud)
require fails silently, not loading foo.pm6, and bar is not found. This also fails:
require foo;
say bar;
Run Code Online (Sandbox Code Playgroud)
with the same error, about not finding bar. This file:
require ::"foo";
say bar;
Run Code Online (Sandbox Code Playgroud)
Fails even strangely, with MVMArray: Can't shift from an empty array
UPDATE: it fails silently because it stops when it finds an unknown symbol, bar, …
我正在尝试使用多个分派来重载和使用组合类中的方法。这是实现:
role A {
has $!b;
submethod BUILD( :$!b ) {}
multi method bar () {
return $!b;
}
}
class B does A {
submethod BUILD( :$!b ) {}
multi method bar() {
return " * " ~ callsame ~ " * ";
}
}
my $a = A.new( b => 33);
say $a.bar();
my $b = B.new( b => 33 );
say $b.bar();
Run Code Online (Sandbox Code Playgroud)
但是,此操作失败:
Calling callsame(Str) will never work with declared signature ()
Run Code Online (Sandbox Code Playgroud)
(我真的不知道为什么callame Str用作签名)。更改method bar …
raku ×10
perl6 ×8
rakudo-star ×2
compilation ×1
configure ×1
for-loop ×1
latex ×1
module ×1
pipe ×1
rakudo ×1
read-write ×1
regex ×1
roles ×1
syntax ×1