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

Re: Pre-RFC: A built-in ability for lexical import/export

Thread Previous
From:
Ricardo Signes
Date:
June 24, 2022 16:19
Subject:
Re: Pre-RFC: A built-in ability for lexical import/export
Message ID:
225d57b0-9466-4130-936c-5f9351b2917d@www.fastmail.com
On Fri, Jun 24, 2022, at 11:44, Paul "LeoNerd" Evans wrote:
> Perhaps it should take a whole kv-list of name/ref pairs, so you can export lots in one go:
> 
>   builtin::lexically_export
>     one => \&one,
>     two => \&two, ...
> 
> Though maybe it would be bad to encourage that because really the caller ought to be specifying just a few symbols they want. Hmm.

I think this is great.  I think supplying multiple arguments is fine.  The caller can specify what they want and the callee can behave accordingly.
sub import ($self, @names) {
  die "unknown exports" if @names != grep {; defined } @EXPORTS{ @names };

  builtin::lexically_export %EXPORTS{ @names };
}


> Also, while syntactically this is written out "like a normal function"
> and thus could go in `builtin::`, I wonder if it's a good fit here. It
> can only possibly work during BEGIN time, because it affects the
> compiletime lexical environment of the code being compiled. It isn't
> useful at runtime. It syntactically looks like a regular function but
> it doesn't really behave like one.

I think it's fine.  I don't know that we actually have anything that "looks like it would happen at compile time".  We could perhaps issue a warning if it was called when nothing was being compiled?

-- 
rjbs
Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About