develooper Front page | perl.perl6.language | Postings from March 2005

string/list division

Thread Next
March 28, 2005 09:12
string/list division
Message ID:
It was a matter of time, of course, after my last thread.

How often do we want chunks of a string or list? And how often do we
abuse a temporary copy and substr/splice for that?

What if instead of

    my @copy = @array;
    while (my @chunk = splice @copy, 0, $chunksize) {
    }  # ^1

we could just write

    for @array [/] $chunksize -> @chunk { ... }

and instead of 

    my $copy = $string;
    while (defined(my $chunk = substr $copy, 0, $chunksize)) {
    }  # ^2

we could use

    for $string ~/ $chunksize -> $chunk { ... }

I think it'd make life much easier.

Of course, [/] is subject to the same discussion as the other thread,
and should perhaps be (/) or */.


PS.  # consistency gone mad (expires in 1 day)

^1 Yes, I know it can be made more efficient by using the "list
reference" trick, sub { \@_ }->(LIST).
^2 Same thing, but with \substr. Too bad there is only one LVALUE,
because you can't keep a reference around. Will this be fixed in P6?

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About