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

Re: Pre-RFC: yield true feature

Thread Previous | Thread Next
Paul "LeoNerd" Evans
June 10, 2022 18:21
Re: Pre-RFC: yield true feature
Message ID:
On Mon, 6 Jun 2022 23:05:59 +0100
Neil Bowers <> wrote:

> This is a retrospective Pre-RFC for a proposal from Curtis, for which
> he submitted a draft RFC[1]. 
> [1]

haarg then defines[2] three possible ways that such a feature might
work in practice, summarized as:

  1. Implicit return value is ignored and `true` is substituted instead

  2. The surrounding `require` would ignore the implicit return value
     and behave as if `true` had been returned

  3. The surrounding `require` would ignore *any* return value (whether
     implicit because of EOF, or explicit from `return`), and behave as
     if `true` had been returned


Option 1 differs from options 2 and 3 in that option 1 is more about
the implied meaning of the contents of the loaded file itself, whereas
options 2 and 3 affect only what `require` will do with that
information. This matters because sometimes code uses `do` on a file
instead, and expects the resulting value obtained from it to be
meaningful (e.g. as configuration or similar). Option 1 would affect
that usecase, whereas options 2 and 3 would not.

Option 3 differs from options 1 and 2 when we consider the current
behaviour that modules can *explicitly* `return false` to signal a
particular kind of error, distinct from actually `die`ing. (In brief:
it has to do with whether subsequent attempts to `require` the file
again will result in another compilation attempt, or simply rethrow the
previous failure). haarg also comments:

> I'm not particularly convinced that allowing the module to be
> recompiled is a useful feature, so I don't think the "return false"
> behavior needs to be facilitated under this feature. But others may
> disagree, and this would argue against the third option I proposed
> above.

I agree; I don't think allowing recompilation is useful. In the rare
event that maybe some module did want to do that, perhaps it could
specifically signal this with

   no feature yield_true;
   return 0;  # request recompilation

The vastly-common case would not want to do that, so it seems most
expedient not to consider it here.

Therefore I think we should go with option 3; which would involve
altering the implementation of `require` to just ignore the return
value of the loaded file if `feature 'yield_true'` was in effect by the
time it reached EOF and hadn't already thrown an exception by that time.

Paul "LeoNerd" Evans      |  |

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About