use constant is an ugly hack that breaks lots of syntax (e.g. here)
Nicer would be:
const $ten = 10;
This would a normal lexical that behaves the same as any other normal lexical, but is subject to constant-folding in the same way that constant subs are now.
A new keyword is proposed, rather than say a :const attribute, because the expression on the righthandside is evaluated at BEGIN time:
say "2";
const $x = say "1";
say "3";
(the output is printed in numerical order)
Were this written as my $x :const = say "1" it would be lot more subtle to explain why (and implement) the side-effects happening at BEGIN time.
use constant
is an ugly hack that breaks lots of syntax (e.g. here)Nicer would be:
This would a normal lexical that behaves the same as any other normal lexical, but is subject to constant-folding in the same way that constant subs are now.
A new keyword is proposed, rather than say a
:const
attribute, because the expression on the righthandside is evaluated atBEGIN
time:(the output is printed in numerical order)
Were this written as
my $x :const = say "1"
it would be lot more subtle to explain why (and implement) the side-effects happening at BEGIN time.