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