develooper Front page | perl.perl5.porters | Postings from April 2022

Re: Pre-RFC: a `library` keyword

Thread Previous | Thread Next
From:
Graham Knop
Date:
April 5, 2022 08:06
Subject:
Re: Pre-RFC: a `library` keyword
Message ID:
CAM=m89HjdyDLJ4_8Y3zmnkJzoUjONQEsS4vboGupbq8v==A-+w@mail.gmail.com
On Tue, Apr 5, 2022 at 5:56 AM Yuki Kimoto <kimoto.yuki@gmail.com> wrote:
>
>
>
> 2022-4-4 19:27 Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> wrote:
>>
>> Yuki Kimoto <kimoto.yuki@gmail.com> writes:
>>
>> > I ask a question about  yield_true feature.
>> >
>> > This example seems to be adding "1;" to the end of the file scope.
>> >
>> > Can yield_true feature be implemented actually as a file scope, not as a
>> > global scope?
>>
>> All features (as in feature.pm) are lexically scoped, the file scope is
>> just the top-level lexical scope.  This implies that doing `use feature
>> 'yield_true';` in a non-toplevel scope, i.e. inside a sub or other
>> block, has no effect, since the feature will not be enabled anymore at
>> the end of the file scope.
>>
>> - ilmari
>
>
> Thank you for your reply.
>
> Can I understand the yield_true feature as the following example?
>
>   {
>     use feature 'yield_true';
>     {
>       print "Hello';
>     }
>   }
>
> is same as
>
>   {
>     {
>       print "Hello';
>     }
>     1;
>   }
>

It wouldn't make any sense for this to apply to inner blocks. It would
only apply to the end of the file. Since the feature would usually be
enabled at the beginning of a file, it would be in effect for all
inner blocks. Having all inner blocks in a file return true would not
make sense.

There is more discussion about this potential feature on the RFC:
https://github.com/Perl/RFCs/pull/16

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