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

Re: Pre-RFC Deep constants

Thread Previous | Thread Next
March 9, 2023 18:40
Re: Pre-RFC Deep constants
Message ID:
I think Perl needs constants in the core. The issue with blessed references
(or Corinna objects), can be vexing, so I'll punt on that, but native
constants are a needed feature and trying to choose from amongst the
various CPAN modules isn't fun. If you just have scalars, some people
(including me), still use sub foo() { 'frobnicate' }, but that's obscure if
you don't understand what the empty prototype is doing there, or how the
contents of the sub body impact behavior.

On Thu, Mar 9, 2023 at 5:58 PM Robert Rothenberg <> wrote:

2. An attribute
>    my $var :readonly = ....

I would vote for an attribute. The builtin:: namespace is there, in part,
because Perl is already huge, and we're struggling to find ways to
introduce new core behavior without breaking existing code. There are a few
times new syntax has been proposed which conflict with punctuation
variables, too. Perl's huge.

Attributes are a way of adding new behavior which is less likely to
conflict. However, I think attributes should *generally* be reserved for
behavior which augments existing behavior. Using my $foo :constant = ...;,
we're taking an existing language construct and augmenting this.

I think this actually fits the linguistic nature of Perl. Think of
attributes as adjectives modifying a noun. If something should be an
adjective, making it an attribute is a clean way and mostly safe way of
extending Perl.

If we have a proliferation of attributes, that might be an issue, too, but
if we think about the "noun" as a namespace, we could possibly reuse
existing attributes. The :const attribute is defined as this:

           This experimental attribute, introduced in Perl 5.22,
           only applies to anonymous subroutines.  It causes
           the subroutine to be called as soon as the "sub"
           expression is evaluated.  The return value is captured
           and turned into a constant subroutine.

But saying my $foo :const = ...; is clearly using the "adjective" in a
different context, so it can be evaluated differently. Whether or not this
is something that's likely to be a source of confusion is something I'm
unsure about.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About