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

Re: key/value hash and index/valuse array slices syntax

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
July 4, 2013 01:01
Subject:
Re: key/value hash and index/valuse array slices syntax
Message ID:
DDB150BF-0F1D-4672-93D3-99ABDA3B4B2E@cpan.org

On Jul 3, 2013, at 1:12 PM, Ruslan Zakirov <ruz@bestpractical.com> wrote:

> 
> 
> 
> On Mon, Jul 1, 2013 at 7:27 PM, Father Chrysostomos <sprout@cpan.org> wrote:
> 
> On Jul 1, 2013, at 5:52 AM, Ruslan Zakirov <ruz@bestpractical.com> wrote:
> 
>> 
>> 
>> 
>> On Sun, Jun 16, 2013 at 11:31 PM, Father Chrysostomos <sprout@cpan.org> wrote:
>> 
>> On Jun 16, 2013, at 11:47 AM, Ruslan Zakirov <ruz@bestpractical.com> wrote:
>> > I want to reject most lvalue operations:
>> >
>> > 1) %h{a} = ... as well as %h{qw(a b)} = ... should throw an error
>> >
>> > 2) I think lvalue subs should too as it's assignment
>> 
>> $ ./perl -Ilib -le '$_ = "hello"; (sub : lvalue { %{{"hello" => 2}}{$_} }->()) = 3; print $_'
>> 3
>> 
>> Can I check during compile time that an op is used as return value of a lvalue sub? LVRET is runtime thing. Can not find example in the code. A pointer or a list of flags to look at?
> 
> Look for OPpMAYBE_LVSUB in op.c:op_lvalue_flags.  Without that flag, LVRET always returns 0 at run time.
> 
> Yep, that part I figured and know how to check it during runtime. However, in this case I think error should be thrown during compile time. Flag only suspects lvalue sub and LVRET does additional job to confirm situation. As far as I can see LVRET only works during runtime (may be I'm wrong). I should dig more and try a few things, it's possible that I just don't see obvious thing at the moment. 

Lvalue subs can be called in rvalue context.  So the only right thing to do here is to treat the return value like the arguments to for(...).


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