G'day All,
I'm intending to propose export tags for the builtin pragma.
I'd appreciate any comments you may have about this. Thankyou.
A Brief History of the 'builtin' Pragma
-
First introduced as an experimental pragma in Perl v5.36.0. See:
-
Still experimental in Perl v5.38.0. See:
-
In the development version of Perl v5.39.2,
the experimental status was removed from many of the builtin pragma functions. See:
My Usage of the 'builtin' Pragma
When released, I often play around with experimental features;
however, I never use them in production-grade code.
I did the same with the builtin pragma and found many to be useful:
in some cases, I also found the import lists to be quite unwieldy.
When Perl v5.40.0 is released, presumably sometime next year,
I will probably start using many of the stable functions provided by the builtin pragma in production-grade code.
I would like easier to use import lists; accordingly, I'm proposing a number of export tags.
Proposed Export Tags for the 'builtin' Pragma
- :bool
-
Exports: true, false, is_bool.
- :weak
-
Exports: weaken, unweaken, is_weak.
- :ref
-
Exports: blessed, refaddr, reftype.
- :round
-
Exports: ceil, floor.
- :stable
-
Exports all stable (i.e. non-experimental) functions.
- :all
-
Exports all functions.
Re: RFC: Export tags for builtin pragma
by choroba (Cardinal) on Oct 19, 2023 at 18:17 UTC
|
I love the idea! Thank you for moving it forward.
If I had to nitpick, it would probably be about the chosen names:
- I'm not sure about the :ref, as :weak are also about references, so someone could be surprised :ref doesn't include :weak.
- :round is usually a function of its own (see POSIX) but it's not part of :round, which might again be confusing. Maybe :rounding? It's a bit longer than the rest, though...
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
| [reply] [d/l] |
|
G'day choroba,
++ Thanks for the feedback.
None of those tag names are set in stone.
I'm certainly open to suggestions for alternatives.
For your point 1, maybe:
-
:weak - weaken, unweaken, is_weak
-
:refinfo - blessed, refaddr, reftype
-
:ref - :weak, :refinfo
For point 2, I wasn't entirely sold on :round myself but couldn't think of anything better.
Perhaps await suggestions from others.
| [reply] |
|
Maybe :numeric instead of :round? That provides some future proofing in the event functions like looks_like_number are added at a later date.
Although maybe that causes issues as then different module versions would load different subs.
| [reply] [d/l] [select] |
|
Re: RFC: Export tags for builtin pragma
by Haarg (Priest) on Oct 20, 2023 at 01:17 UTC
|
The problem with tags like this is that adding anything to them later is essentially a compatibility break. I'd say they are pretty unlikely to be added.
With Perl 5.40, when they start being stabilized, it will be possible to import all of the stable builtins using a version tag, similar to features.
| [reply] |
|
G'day Haarg,
++ Thanks for your opinion.
"I'd say they are pretty unlikely to be added."
I'll see what others have to say; however, on the basis of "nothing ventured, nothing gained", I may still test the waters.
[large unlikelihood = small likelihood :-) ]
| [reply] |
|
I'd rather just see them imported as part of "use v5.40". Any reason not to just import them all? Most of these have been occupying our module namespace for decades anyway.
| [reply] |
Re: RFC: Export tags for builtin pragma [Proposal dropped]
by kcott (Archbishop) on Oct 26, 2023 at 08:19 UTC
|
Thanks to all who provided feedback.
Unfortunately, I've decided to drop this proposal; there are two main reasons.
Firstly, I see in "Perl v5.39.4: perldelta", under
"Updated Modules and Pragmata",
that builtin will allow a :5.40 tag (and presumably higher version numbers in subsequent releases)
which has the same functionality as my proposed :stable tag.
Secondly, there was lack of consensus on many of the proposed tags; e.g.
should :weak be included in :ref;
was :round a good name.
When Perl v5.40.0 is released, I'll probably just be writing:
use builtin ':5.40';
unless I only want a restricted set, such as
use builtin qw{true false};
Thanks again to all who participated in this RFC.
| [reply] [d/l] [select] |
|
The intent is that use v5.40; will automatically do the equivalent of use builtin ':5.40';. This hasn't been implemented yet, but it should be by the time of the final release.
| [reply] [d/l] [select] |
|
| [reply] |
|
|