为什么 Perl 6 序列 'A' ... 'AA' 只有一个元素? [英] Why does the Perl 6 sequence 'A' ... 'AA' have only one element?
问题描述
今天我注意到序列 'A' ... 'AA'
只包含一个元素:
<代码>>'A' ... 'AA'(一种)
我认为它会包含 27:字母加上最后的 AA
.
如果我明确提供一个生成器,它会:
<代码>>'A', *.succ ... 'AA'(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA)
文档说默认生成器是 *.succ
或 *.pred
取决于端点的比较方式.但是:
<代码>>'A' cmp 'AA'较少的
所以看起来我应该默认使用 *.succ
生成器.我绝对没有得到 *.pred
生成器:
<代码>>'A', *.pred ... 'AA'递减超出范围在 <unknown file> 的任何代码中1号线
这是怎么回事?
查看使用的代码:rakudo/operators
您的代码与
非常相似"A", *.succ ...^ * gt "AA"
("B" gt "AA"
是 True
)
和 Curt Tilmes 的代码类似
"A", *.succ ...^ {$_ gt "ZZ" or .chars >"ZZ".chars}"A", *.succ ...^ {$_ gt "YY" 或 .chars >"YY".chars}
("Z" gt "YY"
和 "AAA".chars > "ZZ".chars
是 True
)>
Today I noticed that the sequence 'A' ... 'AA'
contains only one element:
> 'A' ... 'AA'
(A)
I thought it would contain 27: the alphabet plus the final AA
.
If I explicitly provide a generator, it does:
> 'A', *.succ ... 'AA'
(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA)
The docs say that the default generator is either *.succ
or *.pred
depending on how the end points compare. But:
> 'A' cmp 'AA'
Less
So it seems I should be getting the *.succ
generator by default. I'm definitely not getting the *.pred
generator:
> 'A', *.pred ... 'AA'
Decrement out of range
in whatevercode at <unknown file> line 1
What's going on here?
see which code it is used: rakudo/operators
your code is very similar to
"A", *.succ ...^ * gt "AA"
("B" gt "AA"
is True
)
and code by Curt Tilmes is similar to
"A", *.succ ...^ {$_ gt "ZZ" or .chars > "ZZ".chars}
"A", *.succ ...^ {$_ gt "YY" or .chars > "YY".chars}
("Z" gt "YY"
and "AAA".chars > "ZZ".chars
are True
)
这篇关于为什么 Perl 6 序列 'A' ... 'AA' 只有一个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!