小编Jo *_*als的帖子

日期对象“忘记”格式化程序?

使用Perl6的Date时,格式化器对象的处理是否存在错误?如果我在实例化该对象之后操纵日期,则好像格式化程序返回到默认值。

my $d = Date.new(2019, 12, 25, formatter => { sprintf "%02d/%02d in %04d", .month, .day, .year });
# Outputs 12/25 in 2019

$d.later(:1day)
# Outputs 2019-12-26
Run Code Online (Sandbox Code Playgroud)

我希望在调用.later方法之后的输出为“ 2019年12月26日”。

当在GitHub上查看Date.pm6时-https: //github.com/rakudo/rakudo/blob/master/src/core/Date.pm6-我看到.later 方法使用.new创建了新的Date对象而不参考设置的格式化程序。即应该行151

self.new-from-daycount(self.daycount + $multiplier * $amount )
Run Code Online (Sandbox Code Playgroud)

宁愿像

self.new-from-daycount(self.daycount + $multiplier * $amount, &!formatter )
Run Code Online (Sandbox Code Playgroud)

如果是这样,不仅在.later,而且在.succ,.pred等地方,很多地方都缺少这种情况。

perl6 raku

6
推荐指数
1
解决办法
84
查看次数

Use of implicit parameter in for-loop causes hang

Consider the following code

my $a = "AABBCCBGG";
say join "\n", do for $a.comb.squish {
  $a ~~ s/^ ($_+) //;
}
Run Code Online (Sandbox Code Playgroud)

versus

my $a = "AABBCCBGG";
say join "\n", do for $a.comb.squish -> $b {
  $a ~~ s/^ ($b+) //;
}
Run Code Online (Sandbox Code Playgroud)

The first hangs forever while the last executes as expected. Is this an error or is there some finer detail while using the implicit $_ that I don't understand? Using Rakudo Star 2019.03.01.

perl6 raku

6
推荐指数
1
解决办法
92
查看次数

标签 统计

perl6 ×2

raku ×2