develooper Front page | perl.perl5.porters | Postings from May 2016

[perl #128187] Make list assignment to sub :lvalue{keys} an error

Thread Previous
Father Chrysostomos
May 19, 2016 18:30
[perl #128187] Make list assignment to sub :lvalue{keys} an error
Message ID:
# New Ticket Created by  Father Chrysostomos 
# Please include the string:  [perl #128187]
# in the subject line of all future correspondence about this issue. 
# <URL: >

With the %hash{'key'} syntax, which is not an lvalue, we have an error if it is the last statement in an lvalue sub and the lvalue sub is assigned to.  However, if the lvalue sub call is in foreach(...) or referenced by \ we have no error.

So, given

    sub foo :lvalue { %hash{'key'} }

the first line is permitted, but the second one dies:

    foo = 3;

even though these are both variants of lvalue context.

I propose extending that to keys() returned from an lvalue sub in a list assignement.  Currently, this works:

    sub foo :lvalue { keys %h }
    foo = 1024;

But this does not die, yet does nothing useful, and is probably a mistake wherever it occurs:

    sub foo :lvalue { keys %h }
    (foo) = 1024;  # I want this to die.

whereas the plain form of list assignment to keys *does* die at compile time:

    (keys %h) = 1024; # Can't modify keys in list assignment

The reason I bring this up is that, with the demise of autoderef, the one thing standing in the way of making &CORE::keys() work is gone, and I am trying to implement it now.  It will be much easier to make this behave the same way as a bare keys()--

    &CORE::keys(\%h) = 1024; # ok; scalar assignment
    (&CORE::keys(\%h)) = 1024; # not ok; list assignment

--if I can disallow keys in the circumstance described above.  After all, &CORE::keys will be an lvalue sub with ‘keys’ (or the next best thing) as the last op.

I intend to go ahead and make this change soon (whatever soon means), but you still have until next year’s code freeze to object. :-)


Father Chrysostomos

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About