On 2012-06-25 Reini Urban via RT wrote: > On Mon, Jun 25, 2012 at 10:33 AM, Father Chrysostomos via RT > <perlbug-followup@perl.org> wrote: > > On Mon Jun 25 07:29:17 2012, rurban wrote: > >> and it should be an error. > > > > Why? If my can take a list, why not an empty one? > > my is perl's declaration syntax. It expects one or many lexical > variable names, not zero. No, it expects exactly one variable name, or a list of variables enclosed in parens. And lists can be empty. > lexicals are our default, non lexicals are warned. > Empty declarations are syntax errors, if "my ();" or "my ;" Yes, and we should fix the first one. I disagree that it's purely a syntax error because the grammar clearly allows it and it has an obvious interpretation. > >> If the compiler detects an invalid declaration it > >> should help the author and not silently allow to do nothing. > > > > What is invalid about an empty list? > > It is an empty declaration, which is an syntax error. > empty lists rhs are perfectly valid, even in declarations > such as: > my ($a,$b) = (); > but not in a lhs declaration. () = 42; works fine. It also has an obvious interpretation: if the LHS is shorter than the RHS, the remaining items are ignored. In this case the LHS has zero elements and all values in the RHS list are ignored. "lhs declaration" isn't a meaningful concept: Syntactically speaking you can add add "my" in front of a variable in any valid expression. It doesn't matter whether it's the LHS of anything. > >> Re the consistency argument: Why allow now empty declarations? This > >> makes it inconsistent. > >> > >> Why should "my ();" parse correctly? > >> Why should "my;" parse correctly? Both are clearly syntax errors. "my ()" should parse correctly because you'd have to introduce a special case to disallow it. (I'm talking about Perl here, not perl. I don't care much about how it's implemented.)Thread Previous | Thread Next