develooper Front page | perl.perl5.porters | Postings from March 2023

Re: Pre-RFC Deep constants

Thread Previous | Thread Next
From:
demerphq
Date:
March 10, 2023 14:24
Subject:
Re: Pre-RFC Deep constants
Message ID:
CANgJU+UsHFEqik=4UOS-5RbsSWgYkuCK01g_YBkxsbZFca330Q@mail.gmail.com
On Thu, 9 Mar 2023 at 20:59, Dan Book <grinnz@gmail.com> wrote:
>
> On Thu, Mar 9, 2023 at 2:50 PM Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:
>>
>> One complication I can immediately see is that, I presume by "deep
>> constant" you would want this entire thing to be readonly:
>>
>>   const $x = [ [ 1, 2, 3 ] ];
>>
>> But what about references to *existing* variables that happen to be
>> found inside a data structure:
>>
>>   my @nums = ( 1, 2, 3 );   # normal mutable array variable
>>   const $y = [ \@nums ];
>>
>> How would perl tell the difference between the two?
>
>
> To me what people are looking for is read only structures. Thus 1. we need an actual read only mechanism for hashes (restricted hashes are too restrictive for this purpose), and 2. in your example the declaration would cause @nums to also become read only.

Yeah, restricted hashes are too restricted for most peoples taste. It is a pity.

I think the solution to the question of @nums is pretty simple: the
constant *isnt* the argument to the constant, but a deep copy which is
read only. So @nums could be changed afterwards, without altering the
constant.

Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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