<?xml version="1.0" encoding="windows-1252"?>
<node id="369627" title="Re^3: Quantum Weirdness and the Increment Operator" created="2004-06-25 10:28:55" updated="2005-06-28 18:19:10">
<type id="11">
note</type>
<author id="249603">
halley</author>
<data>
<field name="doctext">
"Results are undefined" in Computer Science means, "the documentation is not going to explain what you'll get in Tuesday's version of the compiler on John's favorite machine."

&lt;p&gt;In the case of &lt;code&gt;keys %foo&lt;/code&gt;, the results are defined:  you will get all keys.  The order they're returned is defined but poorly so:  it's a mistake for documentation to say they are returned in "random order," because the order has nothing to do with a PRNG.  It would be better to say the order is not defined, as that is more accurate.  Tuesday's compiler on John's machine will produce something inconsistent with your own experiments.

&lt;p&gt;In the case of &lt;code&gt;++$m + $m++&lt;/code&gt;, the results are undefined:  no documentation claims to give an authoritative answer on such expressions, and some documentaion will specifically disavow any predictable results.

&lt;p&gt;For those who do not program in C, here's the gist of the action.  The &lt;code&gt;do { my $x = $m; $m++; $x }&lt;/code&gt; mechanism is not a sufficient postincrement operator, because real post-incrementation happens &lt;b&gt;after the rest of the expression&lt;/b&gt;.  However, the specific moment that is defined to be after the rest of the expression is not clearly defined; various versions of a C compiler will differ, and various hardware platforms may also have something to say about it.  It's undefined.

&lt;div class="pmsig"&gt;&lt;div class="pmsig-249603"&gt;
&lt;p&gt;--&lt;br&gt;&lt;tt&gt;&amp;#91; e d @ h a l l e y . c c &amp;#93;&lt;/tt&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
369247</field>
<field name="parent_node">
369461</field>
</data>
</node>
