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

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

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
July 7, 2012 21:43
Subject:
Re: [perl #113554] my() with empty list causes weird error
Message ID:
20120708044258.GP28886@fernweh.plasmasturm.org
* Ricardo Signes <perl.p5p@rjbs.manxome.org> [2012-07-06 05:40]:
> * Ricardo Signes <perl.p5p@rjbs.manxome.org> [2012-06-25T20:38:46]
> > It seems open to change.  The question is: what's the cost, and
> > what's the benefit?
>
> I think the feature seems low in both cost and benefit, with the key
> difference that once we allow "my();" we will be hard pressed to
> disallow it later, if we realize we should, as we'll be breaking
> something. I'm not entirely opposed to breaking code at the edges of
> sanity, but it sounds like there's very little practical argument to
> make this edge case permitted. Allowing "my()" won't really make it
> act like "normal" built-ins. It will make it a little more like one,
> but not enough to be worth even the relatively small risk of future
> headaches.

I find Jesse Luehr’s argument that

    my ($foo, (), $bar) = (1, 2)

is currently an error for no good reason convincing enough. Now maybe

    my ();

should not work anyhow, but I find that the former definitely should, no
matter whether the latter does.

And if in permitting the former it takes extra code to make the latter
forbidden, then I say give it pass and let the latter be permitted too.

Now, all that said:

As far as banning the latter, I see no sensible argument of my own and
none that has been brought up in this thread other than a gut reaction
of “that just doesn’t look right!”. Maybe so, but why?

Sure it makes little sense to declare a list of no elements, but does it
make more sense to write

    \()

to distributively take references to zero variables, say? Yet that one
is allowed. So what of the following?

    $ perl -E'say for \($x,$y)'
    SCALAR(0x8078654)
    SCALAR(0x80786f4)

    $ perl -E'say for \my ($x,$y)'
    SCALAR(0x8078650)
    SCALAR(0x8078678)

    $ perl -E'say for \()'

    $ perl -E'say for \my ()'
    Can't declare stub in "my" at -e line 1, at EOF
    Execution of -e aborted due to compilation errors.

Why would the last example here be the odd one out? What makes an empty
list so abhorrent in the vicinity of `my` that unlike anywhere else in
Perl, there it has to be forbidden?

Now, all that again said:

In the final analysis this is a rather minor (one and a half) wart, and
if the language retains it I won’t shed all too many tears.

But it is a wart nonetheless.

-- 
*AUTOLOAD=*_;sub _{s/::([^:]*)$/print$1,(",$\/"," ")[defined wantarray]/e;chop;$_}
&Just->another->Perl->hack;
#Aristotle Pagaltzis // <http://plasmasturm.org/>

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