此代码按预期工作:
use v6.d;
class Foo {
has $.name;
submethod BUILD (:$!name = 'John') {};
}
my $f = Foo.new;
say $f;
# OUTPUT: Foo.new(name => "John")
Run Code Online (Sandbox Code Playgroud)
但是,当我添加:
class Bar is Foo {
submethod BUILD (:$!name = 'Jane') {};
}
my $b = Bar.new;
say $b;
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
===抱歉!=== 编译 scrap.raku 时
出错 属性$!name
未在 Bar 类中
声明scratch.raku:14
如何在构建时分配默认值?
我想使用vim的conceal
命令来隐藏我所有的POD6。我试过了
syntax match rakuPodPrefix /^=begin/ conceal cchar=>
Run Code Online (Sandbox Code Playgroud)
没有成功。
foldexpr
或者,把 POD6 全部折叠起来有什么好处呢?我的 vimscript 还不能胜任这项任务。
安装 Rakudo\xe2\x84\xa2 v2023.08 后,我每次都会收到以下错误运行 raku 命令(无论是脚本还是单行命令)时,
\n\n\n发现 1 处已弃用的代码。\n============================================== =========================================
\nraku 库路径中的 .pm 文件扩展名位于:
\n文件#/Users/jimbollinger/lib,第 0 行
\n请使用 raku 模块的 .rakumod 扩展名,或者包含显式声明每个 raku 模块文件的 META6.json 文件。
\n
\n请联系作者以修改这些已弃用的代码,以便此消息消失!
\n
/Users/jimbollinger/lib
是一个目录。
是什么原因导致此错误以及如何修复此错误?
\n给出以下代码:
sub foo {
say 'Hello';
}
my $call_me = 'foo';
Run Code Online (Sandbox Code Playgroud)
我如何调用sub foo
using $call_me
?
我知道,这是一个令人困惑的标题。但代码应该很清楚:
class A {
has $.foo = 1;
# how can I access B::bar from here?
}
class B {
has $.bar = 2;
has A $.a;
submethod TWEAK {
$!a = A.new;
}
}
my $b = B.new;
say $b; # B.new(bar => 2, a => A.new(foo => 1))
say $b.a; # A.new(foo => 1)
my $test := $b.a;
say $test; # A.new(foo => 1)
Run Code Online (Sandbox Code Playgroud)
鉴于$test
,我如何访问 B::bar (与 $test 处于同一“级别”)?
#!/usr/bin/env raku
use Inline::Perl5;
use Smart::Comments:from<Perl5>;
my $foo = 42;
### $foo
say "Done";
Run Code Online (Sandbox Code Playgroud)
预期输出:
### $foo: 42
Done
Run Code Online (Sandbox Code Playgroud)
实际输出:
Done
zsh: segmentation fault raku sc-test.raku
Run Code Online (Sandbox Code Playgroud)
Smart::Comments
是依赖Perl5源码过滤的问题吗?
当我反复运行这段代码时,
\nsrand 1;\nmy @x = (1..1000).pick: 100;\nsay sum @x;\n\n
Run Code Online (Sandbox Code Playgroud)\n我每次都会得到不同的答案。如果我正在重置,srand
为什么它不应该每次都产生相同的随机数?
该错误发生在 REPL 中。
\n该文件中出现错误:
\nuse v6.d;\n\nsrand 1;\nmy $x = rand;\nsay $x; # OUTPUT: 0.5511548437617427\n\nsrand 1;\n$x = rand;\nsay $x; # OUTPUT: 0.308302962221659\n\nsay $*KERNEL; # OUTPUT: darwin\n\n
Run Code Online (Sandbox Code Playgroud)\n我在用着:
\n欢迎使用 Rakudo\xe2\x84\xa2 v2022.07。\n实现 Raku\xc2\xae 编程语言 v6.d。\n基于 MoarVM 版本 2022.07 构建。
\nuse v6.d;
my Str $foo = 'Hello';
my constant $BAR = "--$foo--";
say $BAR;
Run Code Online (Sandbox Code Playgroud)
Use of uninitialized value element of type Str in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful.
in block at deleteme.raku line 4
----
Run Code Online (Sandbox Code Playgroud)
--Hello--
Run Code Online (Sandbox Code Playgroud)
my
没有或 代替our
也会发生同样的事情my
。
[187] > $*DISTRO
macos (12.6)
[188] > $*KERNEL
darwin
[189] > $*RAKU
Raku (6.d)
Run Code Online (Sandbox Code Playgroud)
my $x = prompt "Are you OK? ";
say $x ~~ 'y' ?? "Great!" !! "Bummer";
use Test;
Run Code Online (Sandbox Code Playgroud)
at/ 文件中可以放入哪些测试?它如何响应提示?
当我运行raku --doc test.raku
以下代码时:
#! /usr/bin/env raku
use v6.d;
#| The answer
my Int $bar = 42;
#= Thank you, Douglas
say $bar.WHY.leading;
say $bar.WHY.following;
Run Code Online (Sandbox Code Playgroud)
我没有得到任何输出。当我运行代码(raku test.raku
)时,输出是:
Nil
Nil
Run Code Online (Sandbox Code Playgroud)
有没有办法将声明器块与变量一起使用?
raku ×10
attributes ×2
class ×1
comments ×1
constants ×1
deprecated ×1
filter ×1
fold ×1
inheritance ×1
inline ×1
perl ×1
pod6 ×1
prompt ×1
rakudo ×1
random ×1
srand ×1
string ×1
subroutine ×1
testing ×1
vim ×1