
ruz at bestpractical
Aug 11, 2013, 3:42 AM
Post #1 of 3
(16 views)
Permalink
|
|
blocker of key/value hash slices
|
|
Hi, 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 future. * "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 aliased. * 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 situations: ... 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' feedback. -- Best regards, Ruslan.
|