Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pmichaud (6013)

pmichaud
  (email not shown publicly)
http://www.pmichaud.com/

Patrick Michaud is the pumpking for the Rakudo Perl 6 compiler. He holds a Ph.D. in Computer Science and was formerly a Professor of Computer Science at Texas A&M University-Corpus Christi. He is currently a software developer and consultant focused on open source development and applications, including Perl, PmWiki, and Linux.

Journal of pmichaud (6013)

Friday November 28, 2008
02:42 PM

infix: now works on Ranges in Rakudo

[ #37967 ]
Moritz found a bug in the infix:<Z> operator -- it wouldn't properly zip over a range:

    09:04 <moritz_> rakudo: say (<a b c> Z 1..10).perl
    09:05 <p6eval> rakudo 33300: OUTPUT[elements() not implemented in class 'Range'&#9252;current
                                  instr.: 'infix:Z' pc 4039 (src/gen_builtins.pir:2555)&#9252;]

Normally we would expect this to return a list of lists:

        (("a", 1), ("b", 2), ("c", 3))

The problem here was that infix:<Z> was trying to determine the size of each of its elements by using the 'elements' opcode and then get the individual elements by using a subscript. This failed for two reasons: (1) Ranges don't support postcircumfix:<[ ]>, and (2) Rakudo's implementation of Range didn't work for the 'elements' opcode.

The real approach, as with most things dealing with lists, is to use iterators. I changed the algorithm that it creates an iterator for each argument to infix:<Z>, and then walks those iterators in parallel to build the elements of the final result list. When any of the argument iterators is empty, we're done building the list for infix:<Z>.

As a general rule, I suspect most list operators and builtin functions should not be counting the number of elements or using subscripts to access individual elements of a List. There are likely a few more functions like this in Rakudo that we should be replacing.

Pm
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.