问题
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?
回答1:
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
)
来源:https://stackoverflow.com/questions/52976502/why-does-the-perl-6-sequence-a-aa-have-only-one-element