Sign In/My Account | View Cart  
advertisement


Listen Print

Apocalypse 4
by Larry Wall | Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9

Editor's Note: this Apocalypse is out of date and remains here for historic reasons. See Synopsis 04 for the latest information.

RFC 173: Allow multiple loop variables in foreach statements

Unfortunately, the proposed syntax could also be interpreted as parallel traversal:

  foreach ($a, $b) (@a, @b)

Also the RFC assumes pairs will be passed as two elements, which is no longer necessarily the case. A hash by itself in list context will return a list of pair objects. We'll need to say something like:

    %hash.kv

to get a flattened list of keys alternating with values. (The same method on arrays produces alternating indices and values.)

I like the idea of this RFC, but the proposed syntax is not what I'd like. There are various possible syntaxes that could also potentially fulfill the intent of RFC 120:

    for [$i => $elem] (@array) { }
    for {$i => $elem} (@array) { }
    for ($i, $elem) = (@array.kv) { }

But I like the idea of something that feels like repeated binding. We could use the := binding operator, but since binding is actually the operation performed by formal parameters of subroutines, and since we'd like to keep the list near the for and the formals near the closure, we'll use a variant of subroutine declaration to declare for loops:

    for @list -> $x { ... }         # one value at a time
    for @list -> $a, $b { ... }     # two values at a time

You can un-interleave an array by saying:

    for @xyxyxy -> $x, $y { ... }

Iterating over multiple lists in parallel needs a syntax much like a multi-dimensional slice. That is, something like a comma that binds looser than a comma. Since we'll be using semicolon for that purpose to delimit the dimensions of multi-dimensional slices, we'll use similar semicolons to delimit a parallel traversal of multiple lists: So parallel arrays could be stepped through like this:

    for @xxx; @yyy; @zzz -> $x; $y; $z { ... }

If there are semicolons on the right, there must be the same number as on the left.

Each "stream" is considered separately, so you can traverse two arrays each two elements at a time like this:

    for @ababab; @cdcdcd -> $a, $b; $c, $d { ... }

If there are no semicolons on the right, the values are taken sequentially across the streams. So you can say

    for @aaaa; @bbbb -> $a, $b { ... }

and it ends up meaning the same thing as if the comma were a semicolon, but only because the number of variables on the right happens to be the same as the number of streams on the right. That doesn't have to be the case. To get values one at a time across three streams, you can say

    for @a; @b; @c -> $x { ... }

Each semicolon delimited expression on the left is considered to be a list of generated values, so it's perfectly legal to use commas or "infinite" ranges on the left. The following prints "a0", "b2", "c3", and so on forever (or at least for a very long time):

    for 0 .. Inf; "a" .. "z" x 1000 -> $i; $a {
        print "$a$i";
    }

RFC 019: Rename the local operator

We'll go with temp for the temporizing operator.

In addition, we're going to be storing more global state in objects (such as file objects). So it ought to be possible to temporize (that is, checkpoint/restore) an attribute of an object, or at least any attributes that can be treated as an lvalue.

RFC 064: New pragma 'scope' to change Perl's default scoping

I can't stop people from experimenting, but I'm not terribly interested in performing this experiment myself. I made my short for a reason. So I'm accepting this RFC in principle, but only in principle. Standard Perl declarations will be plainly marked with my or our.

Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9

Next Pagearrow