Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sequence

raku

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?

like image 439
Sean Avatar asked Oct 24 '18 19:10

Sean


People also ask

How many elements are in an array in Perl?

There are only four elements in the array that contains information, but the array is 51 elements long, with a highest index of 50. Perl provides a number of useful functions to add and remove elements in an array. You may have a question what is a function?

What are some examples of numbers in Perl 6 grammar?

For example, 1, 42, 123, or 1000. A grammar in Perl 6 is a special kind of classes with its own keywords. The first rule of the grammar must (by default) be called TOP, and here is the complete program that parses our first set of numbers:

What is Perl 6?

Perl 6 is the long-awaited redesign and reimplementation of the popular and venerable Perl programming language. It’s not out yet–nor is there an official release date–but the design and implementations make continual progress. Innumerable programmers, hackers, system administrators, hobbyists, and dabblers write Perl 5 quite successfully.

How to index an array in Perl with 0 or 1?

Because Perl arrays have zero-based indexing, $ [&] will almost always be 0. But if you set $ [ to 1 then all your arrays will use on-based indexing. It is recommended not to use any other indexing other than zero. However, let's take one example to show the usage of $ [ variable −.


1 Answers

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 )

like image 135
wamba Avatar answered Nov 14 '22 04:11

wamba