On Sun, 12 Mar 2023 at 10:53, Branislav ZahradnÃk <happy.barney@gmail.com> wrote: > > > On Sat, 11 Mar 2023 at 16:50, demerphq <demerphq@gmail.com> wrote: > >> On Sat, 11 Mar 2023 at 15:20, Matthew Persico <matthew.persico@gmail.com> >> wrote: >> >>> How about an MVP that creates just scalar constants? >>> >> >> Huh? We have two ways to create "constant" scalars: >> >> use constant var => "foo"; >> Internals::SvREADONLY((my $var = "x"),1); >> >> Am I missing something? >> >> >> >>> That's got to be 90% of what people need, and then we can add >>> constant hashes later? >>> >> >> We have constant (aka read-only) hashes as well. It is just that they are >> *restricted*, which renders them nearly useless for most purposes. >> >> use Hash::Util qw(lock_hash_recurse); >> lock_hash_recurse(\%hash); >> >> > try: > my $foo = { bar => 1 }; > my %hash = (foo => $foo); > > use Hash::Util qw(lock_hash_recurse); > lock_hash_recurse(%hash); > > $foo->{baz} = 2; > This does what I expect: > > such MVP is imho idea, why not exporting existing behaviour via unified > :const ? > > sub var :const { "foo" } > my $var : const = "x"; > > my %hash : const = ... > my @array : const = ...; > > For mentioned MVP, constant expression should be only: > - literal values > > my $foo : const = { bar => { baz => 1 } }; > > - another already constant structure > > my @foo : const = (1, 2, 3); > my $bar = { foo => \ @foo }; > > - it is constant function or its product > > sub foo : const { ... } > my $bar : const = { foo => \& foo, result => [ foo ] }; > > for MVP, const ffunction may imply :prototype () (like use constant does) > later it may accept const arguments only > > Brano > -- perl -Mre=debug -e "/just|another|perl|hacker/"Thread Previous | Thread Next