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

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

Thread Previous | Thread Next
June 28, 2022 08:53
Re: Pre-RFC: A built-in ability for lexical import/export
Message ID:
On Mon, Jun 27, 2022 at 7:28 PM Dan Book <> wrote:

> I'm concerned about this. Lexical import is designed to limit things to
>> the current scope and not expose them to the outside world. Because you're
>> exporting a reference, it's effectively a global variable. If more than one
>> bit of code imports that reference and alters it, other bits of code might
>> have already taken decisions based on that data, but the assumptions it
>> relied on are no longer true.
>> I don't entirely agree. It's no different in semantics to passing a
> variable to a function, which then has an alias to the variable to operate
> on

I agree with that. What I'm saying is that we shouldn't *add* to the issue.
At least if you export a sub which returns the data structure itself, you
have the option of cloning that structure or marking it read-only.

If we export variables, they would be much safer if they were read-only by
default, but with an option to mutate (e.g., you have to ask for the lack
of safety instead of making it the default):

    lexically_export '$VAR' :mutable => \my $scalar

Otherwise, my vote would be to not support exporting them.

Curtis "Ovid" Poe
CTO, All Around the World
World-class software development and consulting

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