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:
demerphq
Date:
June 26, 2012 00:30
Subject:
Re: [perl #113554] my() with empty list causes weird error
Message ID:
CANgJU+X=uG1qKybjL_T6nviaM-e6NK5n9PwEiT=3U7fOtOGi9Q@mail.gmail.com
On 25 June 2012 22:51, Father Chrysostomos via RT
<perlbug-followup@perl.org> wrote:
> On Mon Jun 25 13:38:28 2012, rurban 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:
>> >> On Sun Jun 24 22:44:27 2012, doy wrote:
>> >> > Fixed in 8b8c1fb. It looks like this was a bug that was fixed during
>> >> the
>> >> > course of MAD development, but was added back into the core with
>> >> #ifdef
>> >> > PERL_MAD just because it was different from the existing core code.
>> >> >
>> >> > (Also, for future reference: 'stub' is the name of the internal perl
>> >> > opcode which generates the '()' construct. See �perl -MO=Concise -
>> >> E'my
>> >> > @x = ()'� for instance.)
>> >>
>> >> I disagree.
>> >>
>> >> The error message is not weird, it is consistent with all perls,
>> >
>> > Not mad builds.
>>
>> Then make MAD consistent with the default non-mad.
>
> That could break code for anyone who is using mad.
>
>>
>> >> 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.
>> lexicals are our default, non lexicals are warned.
>> Empty declarations are syntax errors, if "my ();" or "my ;"
>
> I’m afraid your answer is tautological.  Why *shouldn’t* it be allowed
> to take an empty list?
>
> Allowing an empty list provides a clear benefit and makes things more
> consistent.  What problems could it cause?

It would make debugging difficult. Consider generated code, etc.

I am with Reini on this one, and ill drag in Larry too. Im pretty sure
if Larry thought that

my ();

should be legal it already would be.

That my behaves "a little different" isn't new, we allow the special
use of undef in a my() declaration:

my ($x,undef,$y)= @l;

I contend that allowing my (); would make debugging difficult.  I also
contend that it is meaningless/absurd to "declare zero items".

Does C allow you to write:

int;

?

Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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