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

Re: Pre-RFC Deep constants

Thread Previous | Thread Next
From:
Dan Book
Date:
March 9, 2023 19:59
Subject:
Re: Pre-RFC Deep constants
Message ID:
CABMkAVVwfh1=6BRTZJ5b2a6DwsZ+SYTgahp4jna3ZZboYdfBzQ@mail.gmail.com
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.

-Dan

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