12

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?

Sean
  • 29,130
  • 4
  • 80
  • 105

1 Answers1

6

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 )

Eugene Barsky
  • 5,780
  • 3
  • 17
  • 40
wamba
  • 3,883
  • 15
  • 21