develooper Front page | perl.perl5.porters | Postings from June 2012

Re: [perl #113554] my() with empty list causes weird error

Thread Previous | Thread Next
From:
Jesse Luehrs
Date:
June 25, 2012 18:18
Subject:
Re: [perl #113554] my() with empty list causes weird error
Message ID:
20120626011754.GK30375@tozt.net
On Mon, Jun 25, 2012 at 08:38:46PM -0400, Ricardo Signes wrote:
> * Reini Urban <rurban@x-ray.at> [2012-06-25T19:43:09]
> > Do you really want Perl to compile invalid syntax starting with 5.17
> > just because your code generator sucks?
> 
> It's not invalid syntax forever just because it was once.
> 
> It seems open to change.  The question is: what's the cost, and what's the
> benefit?
> 
> The cost at the language level seems minimal.  It does not allow something
> semantically absurd, just pointless.  Pointless is okay, if it makes things
> simpler under the hood:  perl -e '();;;()=((),,,,())=();;;()'
> 
> The benefit at the language level is very small.  It means that when we say
> "list," we more often consistently mean "empty is okay, too."  It's still not
> great, because we need the parens for the empty list but not a one-element
> list.  But that's close to some other uses.  So it brings things just a little
> closer to consistency.
> 
> So, at the language level, I don't think these changes are too compelling
> either way.  I wouldn't see much reason to pick either keeping or changing
> things, based on that.  (If nothing else, the error message can definitely be
> improved.)
> 
> What about the implementation?  Does it make the life of the implementation
> easier to allow C<my ();> ?

It's basically the same on the implementation side. The change was just
telling it to ignore (with no error) '()' the same way it already
ignores 'undef' in variable declarations, so that now, 'my ($foo, (),
$bar) = (1, 2, 3)' sets $foo to 1 and $bar to 2 rather than throwing an
error, the same way that 'my ($foo, undef, $bar) = (1, 2, 3)' sets $foo
to 1 and $bar to 3.

The reason I made this change was for conceptual clarity more than
anything else - I don't see why variable declarations have to use some
weird special form of list that is different from any other kind of list
in perl. Unless we also want to ban '($foo, (), $bar) = (1, 2, 3)' when
they aren't variable declarations, I don't see why we should be
explicitly banning it here.

-doy

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About