It seems to me that if a lexically scoped yield_true isn't going to behave as I indicated, affecting the results of subroutines as well, then I would say maybe the feature is badly named. Maybe it should be called something like require_treats_this_scope_as_yielding_true. Then it is much more clear that we aren't actually changing the result value of the block or file, that it remains as it was, but rather we are changing the behaviour of require/etc to introspect the source file it is called on and require/etc behaves differently if require_treats_this_scope_as_yielding_true is present in some appropriate place. Different naming makes it more clear if what we are actually changing is how require/etc behave and NOT how the actual code being required behaves, meaning its actual return values. -- Darren Duncan On 2022-06-19 5:57 p.m., Darren Duncan wrote: > 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 DuncanThread Previous | Thread Next