FAQ

* l.mai@web.de via RT [2016-02-05 12:00]:
Am Do 04. Feb 2016, 23:29:24, hmbrand schrieb:
Normally, the part inside the parens scopes to the block connected,
so this does not surprise me.
The difference is that

for (A; B; C) { D }

should be equivalent to

A; while (B) { D } continue { C }

C is executed after A, B, and D. That's why it's surprising that the
loop body D can see and access variables declared in C, even though
their definitions haven't even been executed yet.
Variables declared in the A part of for(A;B;C) do not remain declared
past the loop. If you are serious about strict textual equivalence of
these constructs then that must also bother you. Does it?

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

Search Discussions

  • l.mai@web.de via RT at May 30, 2016 at 6:55 pm

    Am Fr 27. Mai 2016, 04:19:32, aristotle schrieb:
    * l.mai@web.de via RT [2016-02-05 12:00]:
    Am Do 04. Feb 2016, 23:29:24, hmbrand schrieb:
    Normally, the part inside the parens scopes to the block connected,
    so this does not surprise me.
    The difference is that

    for (A; B; C) { D }

    should be equivalent to

    A; while (B) { D } continue { C }

    C is executed after A, B, and D. That's why it's surprising that the
    loop body D can see and access variables declared in C, even though
    their definitions haven't even been executed yet.
    Variables declared in the A part of for(A;B;C) do not remain declared
    past the loop. If you are serious about strict textual equivalence of
    these constructs then that must also bother you. Does it?
    I'm not serious about strict equivalence, let alone textual.

    What bothers me is the time traveling / backwards scoping of C, which comes last in execution order.

    Anyway, the equivalence wrt A can be easily restored by wrapping the whole thing in another scope:

       do { A; while (B) { D } continue { C } };

    It's a bit harder to make 'my $x' not return undef in normal Perl code.

    ---
    via perlbug: queue: perl5 status: open
    https://rt.perl.org/Ticket/Display.html?id=127463
  • Dave Mitchell at May 30, 2016 at 8:28 pm

    On Mon, May 30, 2016 at 11:55:09AM -0700, l.mai@web.de via RT wrote:
    I'm not serious about strict equivalence, let alone textual.

    What bothers me is the time traveling / backwards scoping of C, which comes last in execution order.

    Anyway, the equivalence wrt A can be easily restored by wrapping the whole thing in another scope:

    do { A; while (B) { D } continue { C } };

    It's a bit harder to make 'my $x' not return undef in normal Perl code.
    Just as a data point, the grammar for C<for(;;)> is currently written
    such that in terms of where (lexically speaking) lexical vars are
    introduced and go out of scope,

         for (A; B; C) { D }

    is equivalent to:

         {
             A;
             B;
             C;
             {
                 D;
             }
         }

    --
    Hofstadter's Law: It always takes longer than you expect, even when you
    take into account Hofstadter's Law.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedMay 27, '16 at 11:18a
activeMay 30, '16 at 8:28p
posts3
users3
websiteperl.org

People

Translate

site design / logo © 2018 Grokbase