note
tye
<p>
Hrm, I just noticed a clear mistake in your node.
</p><blockquote><i>
But <tt>scalar</tt> does no such thing.
It changes the way </i>&#91...&#93;<i> the program is compiled, so that the comma operator returns its second operand, instead of constructing a list value.
</i></blockquote><p>
No, the comma operator is actually compiled exactly the same way. What changes at compile time is that a [scalar] op-node is added which changes what the other op-nodes do at <em>run time</em>, preventing them from building a list of scalar values on the stack (well, for most operations that can produce a list of scalar values on the stack, but not for <em>all</em> of them, slices being the most obvious exception).
</p><blockquote><i>
But the context effect applies to the expression itself, not to its value, because all contextual effects occur at compile time, never at run time, and at compile time there are no values; the values do not appear until run time, after all the contextual effects are resolved.
</i></blockquote><p>
No, all contextual effects certainly cannot occur at compile time. A simple counter-example is:
</p><c>
sub contextSensitive { (foo(),bar()) }
contextSensitive();
my $s= contextSensitive();
my @a= contextSensitive();
</c><p>
That code doesn't compile two or three different versions of the contextSensitive() subroutine, one for each possible context. It compiles the <c>(foo(),bar())</c> code exactly one way and at <em>run time</em> the behavior is changed depending on what context the sub was used in.
</p><p>
In fact, my testing shows that most contextual effects occur at run time. Any contextual effects happening at compile time would be optimizations requiring extra code so I'm not surprised that I couldn't find any cases of that. It would also require some static analysis of the parsed code to even determine if the context can be known at compile time. This type of static analysis is pretty rare in perl.
</p>
<div class="pmsig"><div class="pmsig-22609"><p align="right">
- [tye]<tt> &nbsp; &nbsp; &nbsp; &nbsp;</tt>
</p></div></div>
72247
72263