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

Re: Pre-RFC: yield true feature

Thread Previous | Thread Next
From:
Darren Duncan
Date:
June 20, 2022 00:57
Subject:
Re: Pre-RFC: yield true feature
Message ID:
547778fe-7bf1-62cc-4325-99d90fbdc468@darrenduncan.net
On 2022-06-19 5:23 a.m., Dave Mitchell wrote:
> 1) that the yield_true feature is strictly lexically scoped. Because
> otherwise it's a special case.
> 
> 99.9% of the time it will be enabled at the top of the src file, so no one
> will care much. In the rare case that someone does
> 
>      {
>          use v5.40;
>          ... something relying on 5.40 syntax ...
>      }
>      ... normal perl ...
>      0;
> 
> then regardless whether their code makes much sense of not, it should do
> as expected, and croak with "Foo.pm did not return a true value".
> 
> 2) that, regardless of whether the require returns via an explicit
> 'return', or by implicitly falling off the end of the src file, whether
> perl does the "croak if false" test is governed purely by whether
> 'yield_true' was in scope at the last statement executed. I.e. we don't
> distinguish between implicit and explicit returns - again, otherwise it's
> a special case.

So if yield_true is lexically scoped, what do we expect to happen here?

   sub foo {
     use v5.40;
     0;
   }

   my $bar = foo();

   print $bar;

So what does $bar contain?  Does it contain zero or true?

If yield_true is lexically scoped, then we would expect executing the scope 
containing it to return true, which in this case is the subroutine, right?

Likewise, what do we expect here?

   use v5.40;

   sub foo {
     0;
   }

   my $bar = foo();

   print $bar;

In either case, the body of subroutine too is in scope of the yield_true, so 
what do we expect it to return?

-- Darren Duncan

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