<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 21/10/2024 16:08, Archie Cobbs
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CANSoFxs3RSAm-1pwCNz7ub5UpOG7zNCtEB0Y3z611nkmAMiH4Q@mail.gmail.com">
      
      <div dir="ltr">
        <div dir="ltr">On Mon, Oct 21, 2024 at 10:01 AM Maurizio
          Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com" moz-do-not-send="true" class="moz-txt-link-freetext">maurizio.cimadamore@oracle.com</a>>
          wrote:</div>
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            <div>
              <div>
                <p style="margin:0px 0px 1.2em">On 21/10/2024 15:39,
                  Archie Cobbs wrote:</p>
                <div>
                  <blockquote type="cite">
                    <div dir="ltr">
                      <div class="gmail_quote">
                        <div>So no special treatment of loop induction
                          variables is needed.<br>
                        </div>
                      </div>
                    </div>
                  </blockquote>
                </div>
                <p style="margin:0px 0px 1.2em">I’m not sure of that. I
                  mean, I “can see” why you’d think that. But in which
                  scope does STEP belong? Yes, it belongs to the for
                  loop header - but it is executed <i>after</i> the
                  loop. And, in fact, it can even refer to variables
                  that would otherwise be DU outside the loop body:</p>
                <pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;background-color:rgb(248,248,248);white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block">void m() {
   int i;
   for (int j = 0 ; j < 10 ; j = j + i) {
      i = 1; // if this is commented out, error!
   }
}
</code></pre>
                <p style="margin:0px 0px 1.2em">So I’m not sure it is a
                  <i>strict</i> generalization :-)</p>
              </div>
            </div>
          </blockquote>
          <div>Sorry for not being more precise... all that I am
            implying by "generalization" is this:</div>
          <div>
            <ul>
              <li>Let X be a program X that currently does not compile,
                but would successfully compile under the proposal in
                JDK-8341785 (allow capture of basic for() loop
                variables)<br>
              </li>
              <li>Then X would also compile under the <span class="gmail-im">"final or effectively frozen at the
                  point of capture" proposal<br>
                </span></li>
            </ul>
          </div>
        </div>
        <div>Proof: Let v be the variable. It must be the case that v is
          not modified in the body of the for() loop. It must also be
          the case that v is not modified after the for() loop, because
          v is declared in the for()  loop INIT section. It must also be
          the case that the lambda is contained in the body of the for()
          loop. Therefore, it is not possible for v to be modified at
          any point in the source code of the program that lexically
          follows the lambda. Therefore v is <span class="gmail-im">final
            or effectively frozen at the point of capture" with respect
            to that lambda.</span></div>
      </div>
    </blockquote>
    <p>I get that! What I'm saying is that most users will read my above
      example like:</p>
    <pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;background-color:rgb(248,248,248);white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block">for (int j = 0 ; j < 10 ; ) {

   ...
   j = j + i;
}
</code></pre>
    <p>That is a good explanation for what the loop does. But this now
      breaks the generalization (because "j" is now mutated inside the
      body). E.g. the variable "j" is declared in the "for loop"
      statement. It is also modified in the for loop statement (in the
      STEP part). It seems mostly an implementation "trick" that we can
      look at STEP before BODY, so that we can then consider the
      induction variable as "not mutated after it is introduced".</p>
    <p>Maurizio<br>
    </p>
    <p><br>
    </p>
    <blockquote type="cite" cite="mid:CANSoFxs3RSAm-1pwCNz7ub5UpOG7zNCtEB0Y3z611nkmAMiH4Q@mail.gmail.com">
      <div dir="ltr">
        <div><span class="gmail-im">-AC<br>
          </span></div>
        <div><br>
        </div>
        <span class="gmail_signature_prefix">-- </span><br>
        <div dir="ltr" class="gmail_signature">Archie L. Cobbs<br>
        </div>
      </div>
    </blockquote>
  </body>
</html>