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?
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?
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:
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.
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 −.
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With