note
chromatic
<blockquote><em>I guess they do.</em></blockquote>
<p>I hate being cruel... but read the parser.</p>
<blockquote><em>Or is that</em> also <em>a kind of disambiguation (of the match operator)?</em></blockquote>
<p>In one sense, those parentheses only <em>mark</em> the empty list, but it's probably more accurate to say that those <em>do</em> create a list. That's only true for the empty list however, as parsers have a very difficult time identifying invisible, non-existent characters.</p>
<blockquote><em>Hmm.. here they obviously don't force list context?</em></blockquote>
<p>Correct. Why would you expect them to do so? They're immaterial to the expression, just as in <c>my $x = ( 2 + 2 );</c>.</p>
<p>If parentheses did create lists, what would you expect this code to do?</p>
<c>my $x = ( 1 + 2 ) * 3;</c>
<p>Perl doesn't have a strict leftmost-applicative evaluation order, so the parentheses are necessary to disambiguate precedence.</p>
<p>That's the exact reason why the parentheses are necessary to <em>group</em> lists, but do not <em>create</em> lists. In:</p>
<c>my @fib_values = 1, 1, 2, 3;</c>
<p>... the expression <c>my @fib_values = 1</c> is a <em>complete</em> expression to the parser as it is. Now it may be completely unambiguous to you that the entire expression is a list assignment, but there are plenty of more complicated assignment forms that involve mixed expressions such that Perl will give you a warning that it may have guessed wrong in this case.</p>
<p>Note also that you <em>don't</em> need parentheses when passing an argument list to a function or especially a built-in operator... again, unless you need to disambiguate something.</p>
594413
594517