develooper Front page | perl.perl5.porters | Postings from August 2013

blocker of key/value hash slices

Thread Next
Ruslan Zakirov
August 11, 2013 10:42
blocker of key/value hash slices
Message ID:

There is one technical subject at this moment that blocks completion of the
change. It's lvalue usage of key/value hash slices in lvalue functions and
I want to forbid it. Below you can find background of such decision. What
love to get feedback on the subject.

   More on lvalue usages
    There are several lvalue uses:

    *   assignment

            %h{'a','b','c'} = ...;

        Above is disallowed at the moment. The reason to dissallow it as
        it's not clear how to implement it. Naive approach is to just make
        it work like assign to a regular slice where keys are aliased to tmp
        variables (ignored). I don't think this is useful. Useful approach
        is to treat above as delete on left hand side and push what's on RHS
        into the hash. For example this makes the following work as
        discussed "push %h, ...":

            %h{()} = ...;

        Two solutions are orthogonal, so I find it's better to disallow
        assign at all to open door for more advanced solutions in the

    *   "one" element assignment

            %h{'a'} = ...;

        In this example LHS is actually two elements, not one, so it's list
        assignment and should be treated in the same way as previous item.

    *   foreach and friends

            $_++ foreach %h{'a','b'};

        This operation behave in the same way as the following:

            $_++ foreach %h;

        Keys are tmp copies, so updates are thrown away, but values are

    *   lvalue functions

        Considering above you can not return key value hash slices from
        lvalue fucntions.

        As far as I know there is no way to distinguish the following two

            ... for lvalue_sub();
            (lvalue_sub()) = (...);

        So if we allow first then automatically allow the second and it will
        be using naive implementation and we wouldn't be able to change it
        later, so I would prefer to forbid both for now and act using users'

Best regards, Ruslan.

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