Why does the Perl 6 sequence 'A' … 'AA' have only one element?

这一生的挚爱 提交于 2019-12-23 07:32:04

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!