Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

blocker of key/value hash slices

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


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.


sprout at cpan

Aug 11, 2013, 7:49 AM

Post #2 of 3 (9 views)
Permalink
Re: blocker of key/value hash slices [In reply to]

Ruslan Zakirov wrote:
> 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.

I am strongly opposed to forbidding the former. I do not mind one way
or the other about the latter. You can tell the difference at run
time. pp_padav does exactly that:

} else if (PL_op->op_private & OPpMAYBE_LVSUB) {
const I32 flags = is_lvalue_sub();
if (flags && !(flags & OPpENTERSUB_INARGS)) {
... here we know this is assignment ...


ruslan.zakirov at gmail

Aug 11, 2013, 3:57 PM

Post #3 of 3 (8 views)
Permalink
Re: blocker of key/value hash slices [In reply to]

Ruslan from phone.
11.08.2013 17:49 пользователь "Father Chrysostomos" <sprout [at] cpan>
написал:
>
> Ruslan Zakirov wrote:
> > 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.
>
> I am strongly opposed to forbidding the former. I do not mind one way
> or the other about the latter. You can tell the difference at run
> time. pp_padav does exactly that:
>
> } else if (PL_op->op_private & OPpMAYBE_LVSUB) {
> const I32 flags = is_lvalue_sub();
> if (flags && !(flags & OPpENTERSUB_INARGS)) {
> ... here we know this is assignment ...
>

Thanks for the key part.

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.