Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPERIMENT] the :const attribute on subroutines #14428

Open
p5pRT opened this issue Jan 20, 2015 · 8 comments
Open

[EXPERIMENT] the :const attribute on subroutines #14428

p5pRT opened this issue Jan 20, 2015 · 8 comments
Labels
experiment ticket tracking an active experiment

Comments

@p5pRT
Copy link

p5pRT commented Jan 20, 2015

Migrated from rt.perl.org#123630 (status was 'open')

Searchable as RT123630$

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2015

From @cpansprout

The ‘const’ attribute is being added as an experimental feature in perl 5.22.0.
This ticket will collect bugs and other acceptance-criteria tickets to
track before :cosnt can be considered accepted or failed in a
future version of perl.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented May 20, 2016

From @cpansprout

On Mon Jan 19 20​:37​:06 2015, sprout wrote​:

The ‘const’ attribute is being added as an experimental feature in
perl 5.22.0.
This ticket will collect bugs and other acceptance-criteria tickets to
track before :cosnt can be considered accepted or failed in a
future version of perl.

This ticket has had no attention whatsoever. This means that either (a) the feature is bug-free and perfect, or that (b) nobody is using it, or that (c) those who are using it are very silent.

If a is the case, then this feature no longer needs to be experimental.

If b is the case, it should definitely remain experimental.

If c is the case, would somebody please speak up and give opinions on the feature (whether it works and is designed well, whether it is designed poorly, whether it seems like a good design but has bugs, etc.).

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented May 20, 2016

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 20, 2016

From @davidnicol

heavens, it's Warnock's dilemma, extended

On Fri, May 20, 2016 at 4​:36 PM, Father Chrysostomos via RT <perlbug-
<perlbug-followup@​perl.org>

This ticket has had no attention whatsoever. This means that either (a)
the feature is bug-free and perfect, or that (b) nobody is using it, or
that (c) those who are using it are very silent.

If a is the case, then this feature no longer needs to be experimental.

If b is the case, it should definitely remain experimental.

If c is the case, would somebody please speak up and give opinions on the
feature (whether it works and is designed well, whether it is designed
poorly, whether it seems like a good design but has bugs, etc.).

--
"Why would you want to be the last man alive on a sinking ship?" -- Elon
Musk

@p5pRT
Copy link
Author

p5pRT commented May 21, 2016

From @wolfsage

Sounds good to me. Though can we add something like the attached patch
to the documentation for clarity?

-- Matthew Horsfall (alh)

@p5pRT
Copy link
Author

p5pRT commented May 21, 2016

From @wolfsage

Inline Patch
diff --git a/pod/perlsub.pod b/pod/perlsub.pod
index 78de284..f95d5da 100644
--- a/pod/perlsub.pod
+++ b/pod/perlsub.pod
@@ -1707,11 +1707,14 @@ Perl 5.22 also introduces the experimental "const" attribute as an
 alternative.  (Disable the "experimental::const_attr" warnings if you want
 to use it.)  When applied to an anonymous subroutine, it forces the sub to
 be called when the C<sub> expression is evaluated.  The return value is
-captured and turned into a constant subroutine:
+captured and turned into a constant subroutine. If declared inside of
+a C<BEGIN> block, it may also be inlined:
 
-    my $x = 54321;
-    *INLINED = sub : const { $x };
-    $x++;
+    BEGIN {
+        my $x = 54321;
+        *INLINED = sub : const { $x };
+        $x++;
+    }

@rjbs rjbs added experiment ticket tracking an active experiment and removed Severity Low labels Apr 30, 2021
@rjbs rjbs changed the title [EXPERIMENT] :const [EXPERIMENT] the :const attribute on subroutines Apr 30, 2021
@jkeenan
Copy link
Contributor

jkeenan commented Oct 29, 2021

From @wolfsage

Inline Patch

diff --git a/pod/perlsub.pod b/pod/perlsub.pod
index 78de284..f95d5da 100644
--- a/pod/perlsub.pod
+++ b/pod/perlsub.pod
@@ -1707,11 +1707,14 @@ Perl 5.22 also introduces the experimental "const" attribute as an
 alternative.  (Disable the "experimental::const_attr" warnings if you want
 to use it.)  When applied to an anonymous subroutine, it forces the sub to
 be called when the C<sub> expression is evaluated.  The return value is
-captured and turned into a constant subroutine:
+captured and turned into a constant subroutine. If declared inside of
+a C<BEGIN> block, it may also be inlined:
 
-    my $x = 54321;
-    *INLINED = sub : const { $x };
-    $x++;
+    BEGIN {
+        my $x = 54321;
+        *INLINED = sub : const { $x };
+        $x++;
+    }

@wolfsage, do you still want to have this patch applied to pod/perlsub.pod? If so, could you create a p.r.? (I think that would expedite the de-experimentalize-ing of this feature.

Thank you very much.
Jim Keenan

@wolfsage
Copy link
Contributor

wolfsage commented Nov 23, 2021

I think this patch or something like it should be applied for sure. That whole documentation bit is a little messy IMO - it says "inlined" in a bunch of places where I don't think it means what it ... thinks it means. I do not know when I will have time to revisit it though, so expect no action from me here; apologies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experiment ticket tracking an active experiment
Projects
None yet
Development

No branches or pull requests

4 participants