Mailing List Archive

Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables
Currently, each punctuation variable has an $ENGLISH_NAME alias available
for readability. But this has a couple problems: it's only available if you
"use English;" which does not provide a direct indication of the variables
it's related to in the code, and was a significant performance penalty in
older versions of Perl; these issues leading to not much use of the module
and thus the knowledge of their existence has not become widespread; so
average Perl programmers finding $CHILD_ERROR in Perl code are likely not
to know it's an alias for $? or that it's a built-in variable at all, thus
reducing its effective readability instead of increasing it.

Proposed by haarg in https://github.com/Perl/perl5/issues/18699 is to add
aliases like ${^CHILD_ERROR}, using the built-in variable form used for
other more recently added built-in variables.

This has a few advantages: it provides a readable indication of its purpose
like those provided by "use English"; it is clearly a built-in variable to
those who have come across that syntax, and clearly not a regular variable
to those who don't; and it doesn't require an opt-in such as "use English"
as this syntax is already available for Perl to add any new variable names.

The risks are primarily that it doesn't end up being useful and in the
process uses up a bunch of built-in variable names - but reusing the
existing English names for any other purpose strikes me as a poor idea
regardless. It also is likely to be considered uglier than English
variables, due to the extra punctuation required.

This may also be a tangential way to work toward addressing the problem of
rarely-used punctuation variables preventing the use of syntax for other
purposes, such as discussed in https://github.com/Perl/perl5/issues/18393.

-Dan
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
2021-10-30 8:47 Dan Book <grinnz@gmail.com> wrote:

> Currently, each punctuation variable has an $ENGLISH_NAME alias available
> for readability. But this has a couple problems: it's only available if you
> "use English;" which does not provide a direct indication of the variables
> it's related to in the code, and was a significant performance penalty in
> older versions of Perl; these issues leading to not much use of the module
> and thus the knowledge of their existence has not become widespread; so
> average Perl programmers finding $CHILD_ERROR in Perl code are likely not
> to know it's an alias for $? or that it's a built-in variable at all, thus
> reducing its effective readability instead of increasing it.
>
>
One of the most common criticisms of Perl is its low readability.

Although this is partly a hype, I feel it's true that punctuation variables
aren't readable as they are.

Although ${^FOO} is a little peculiar, the word can be searched by
searching engines such as Google, Bing, and I realize it is a special
variable.

I agree with this proposal.
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
Is there anyone who wants to move this proposal forward?

Personally I want to write the following for beginners who don't know the
details of Perl.

# Current
while (my $line = <>) {
if ($. == 1) {
next;
}
}

# Future
while (my $line = <>) {
if (${^INPUT_LINE_NUMBER} == 1) {
next;
}
}
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
On Mon, 13 Dec 2021 08:37:17 +0900
Yuki Kimoto <kimoto.yuki@gmail.com> wrote:

> Is there anyone who wants to move this proposal forward?

I don't think I'd have time to actually implement it myself.

But I don't object to the idea, I think it sounds fine. I can point
someone along the way to where to try implementing it, if a volunteer
appears.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
2021-12-13 19:43 Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:

> On Mon, 13 Dec 2021 08:37:17 +0900
> Yuki Kimoto <kimoto.yuki@gmail.com> wrote:
>
> > Is there anyone who wants to move this proposal forward?
>
> I don't think I'd have time to actually implement it myself.
>
> But I don't object to the idea, I think it sounds fine. I can point
> someone along the way to where to try implementing it, if a volunteer
> appears.
>
>
Thank you.

Is it possible to recruit volunteers if there is no strong opposition to
this proposal?

I have time to spare.
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
This seems like a fine idea and nobody's objected to it yet.

Can you please write it up as a formal RFC on the usual process:

https://github.com/Perl/RFCs/

We have allocated the number 0014 for it.

Thanks,

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
2022-1-22 0:05 Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:

> This seems like a fine idea and nobody's objected to it yet.
>
> Can you please write it up as a formal RFC on the usual process:
>
> https://github.com/Perl/RFCs/
>
> We have allocated the number 0014 for it.
>
> Thanks,
>
>
I will start to write the RFC in a month.
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
On Sat, 22 Jan 2022 09:04:03 +0900
Yuki Kimoto <kimoto.yuki@gmail.com> wrote:

> I will start to write the RFC in a month.

Ah; I thought Dan would write it?

Youtwo should arrange that somehow, to avoid duplicating effort.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
Paul

I thought you replied to my last reply.

> Thank you.
> Is it possible to recruit volunteers if there is no strong opposition to
this proposal?
> I have time to spare.

Dan

Will you write RFC?

>

2022-1-22 23:59 Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:

> On Sat, 22 Jan 2022 09:04:03 +0900
> Yuki Kimoto <kimoto.yuki@gmail.com> wrote:
>
> > I will start to write the RFC in a month.
>
> Ah; I thought Dan would write it?
>
> Youtwo should arrange that somehow, to avoid duplicating effort.
>
> --
> Paul "LeoNerd" Evans
>
> leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
> http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
>
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
On Fri, 21 Jan 2022 15:05:23 +0000
"Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:

> This seems like a fine idea and nobody's objected to it yet.
>
> Can you please write it up as a formal RFC on the usual process:
>
> https://github.com/Perl/RFCs/
>
> We have allocated the number 0014 for it.

Hi Dan,

A nudge to say we're out of the "5.36 release quiet time" now, so this
would be a good time to begin looking into this.

Would you be able to write it up?

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
On Fri, 10 Jun 2022 18:43:02 +0100
"Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:

> On Fri, 21 Jan 2022 15:05:23 +0000
> "Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:
>
> > This seems like a fine idea and nobody's objected to it yet.
> >
> > Can you please write it up as a formal RFC on the usual process:
> >
> > https://github.com/Perl/RFCs/
> >
> > We have allocated the number 0014 for it.
>
> Hi Dan,
>
> A nudge to say we're out of the "5.36 release quiet time" now, so this
> would be a good time to begin looking into this.
>
> Would you be able to write it up?

Hi all,

This has sat pending for a number of weeks now. We still think it's a
good idea, but someone still has to write it up as a real RFC.

A general request, to whomever is interested in having this as a
feature, to have a go at writing this up. If it's still sitting after a
few more weeks we'll call it "Parked" and stop considering it.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
On Sat, Oct 30, 2021 at 1:47 AM Dan Book <grinnz@gmail.com> wrote:

> Currently, each punctuation variable has an $ENGLISH_NAME alias available
> for readability. But this has a couple problems: it's only available if you
> "use English;" which does not provide a direct indication of the variables
> it's related to in the code, and was a significant performance penalty in
> older versions of Perl; these issues leading to not much use of the module
> and thus the knowledge of their existence has not become widespread; so
> average Perl programmers finding $CHILD_ERROR in Perl code are likely not
> to know it's an alias for $? or that it's a built-in variable at all, thus
> reducing its effective readability instead of increasing it.
>
> Proposed by haarg in https://github.com/Perl/perl5/issues/18699 is to add
> aliases like ${^CHILD_ERROR}, using the built-in variable form used for
> other more recently added built-in variables.
>
> This has a few advantages: it provides a readable indication of its
> purpose like those provided by "use English"; it is clearly a built-in
> variable to those who have come across that syntax, and clearly not a
> regular variable to those who don't; and it doesn't require an opt-in such
> as "use English" as this syntax is already available for Perl to add any
> new variable names.
>
> The risks are primarily that it doesn't end up being useful and in the
> process uses up a bunch of built-in variable names - but reusing the
> existing English names for any other purpose strikes me as a poor idea
> regardless. It also is likely to be considered uglier than English
> variables, due to the extra punctuation required.
>
> This may also be a tangential way to work toward addressing the problem of
> rarely-used punctuation variables preventing the use of syntax for other
> purposes, such as discussed in https://github.com/Perl/perl5/issues/18393.
>

I did a first stab at implementing this, and it didn't quite work because
of the way many magical variables are lazily set up on first usage. I would
expect implementing this to involve some serious refactoring of that area
of the code.

Leon
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
2022-7-9 0:49 Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:

> On Fri, 10 Jun 2022 18:43:02 +0100
> "Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:
>
> > On Fri, 21 Jan 2022 15:05:23 +0000
> > "Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:
> >
> > > This seems like a fine idea and nobody's objected to it yet.
> > >
> > > Can you please write it up as a formal RFC on the usual process:
> > >
> > > https://github.com/Perl/RFCs/
> > >
> > > We have allocated the number 0014 for it.
> >
> > Hi Dan,
> >
> > A nudge to say we're out of the "5.36 release quiet time" now, so this
> > would be a good time to begin looking into this.
> >
> > Would you be able to write it up?
>
> Hi all,
>
> This has sat pending for a number of weeks now. We still think it's a
> good idea, but someone still has to write it up as a real RFC.
>
> A general request, to whomever is interested in having this as a
> feature, to have a go at writing this up. If it's still sitting after a
> few more weeks we'll call it "Parked" and stop considering it.
>
>
I'm interested in this topic.

I have questions.

1. Can this be resolved in tokenizer?

This means ${^INPUT_LINE_NUMBER} is replaced with $. in toke.c.

2. Is the brace required?

Is $^INPUT_LINE_NUMBER allowed?

3. Can only the aliases that are often used be added?

For example, in my experience. I use $., $/, $$, $@, $!, $<, $> etc.

If 1 and 3 are ok, I can write RFC.
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
On Sat, 9 Jul 2022 06:14:36 +0900
Yuki Kimoto <kimoto.yuki@gmail.com> wrote:

> I'm interested in this topic.
>
> I have questions.
>
> 1. Can this be resolved in tokenizer?
>
> This means ${^INPUT_LINE_NUMBER} is replaced with $. in toke.c.

No. That's really the variable's name, as can be demonstrated via
softrefs:

$ perl -E '"hello" =~ m/\w+/p; say ${^MATCH}; my $varname = "\cMATCH";
say $$varname'
hello
hello

> 2. Is the brace required?
>
> Is $^INPUT_LINE_NUMBER allowed?

Yes. $^ is already a variable on its own (a little-known part related
to formats).

> 3. Can only the aliases that are often used be added?
>
> For example, in my experience. I use $., $/, $$, $@, $!, $<, $> etc.
>
> If 1 and 3 are ok, I can write RFC.

I'm not sure what significance part 1 has on writing the RFC. That
feels like a purely implementation-level question.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
On Fri, 8 Jul 2022 22:31:51 +0100
"Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:

> > 2. Is the brace required?
> >
> > Is $^INPUT_LINE_NUMBER allowed?
>
> Yes. $^ is already a variable on its own (a little-known part related
> to formats).

I should clarify:

Yes, the brace is required.
No, $^INPUT_LINE_NUMBER is not allowed.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
2022-7-9 6:31 Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:

> On Sat, 9 Jul 2022 06:14:36 +0900
> Yuki Kimoto <kimoto.yuki@gmail.com> wrote:
>
> > I'm interested in this topic.
> >
> > I have questions.
> >
> > 1. Can this be resolved in tokenizer?
> >
> > This means ${^INPUT_LINE_NUMBER} is replaced with $. in toke.c.
>
> No. That's really the variable's name, as can be demonstrated via
> softrefs:
>
> $ perl -E '"hello" =~ m/\w+/p; say ${^MATCH}; my $varname = "\cMATCH";
> say $$varname'
> hello
> hello
>
>
Oh, it is not so easy. Leon seems to have some problems in the stab
implementation.

Softref maybe means symbolic reference.

I changed the question.

Is the alias of the predefined variable the same as the alias such as
"$var" in "for my $var (...)"?


> > 3. Can only the aliases that are often used be added?
> >
> > For example, in my experience. I use $., $/, $$, $@, $!, $<, $> etc.
> >
> > If 1 and 3 are ok, I can write RFC.
>
> I'm not sure what significance part 1 has on writing the RFC. That
> feels like a purely implementation-level question.
>
>
I'm thinking of the problem of *quantity* when I implement them because
predefined variables are too many.

1. RFC-X1 Some part of them
2. RFC-X2 All.

> > > 2. Is the brace required?
> > >
> > > Is $^INPUT_LINE_NUMBER allowed?
> >
> > Yes. $^ is already a variable on its own (a little-known part related
> > to formats).
>
>
> I should clarify:
>
> Yes, the brace is required.
> No, $^INPUT_LINE_NUMBER is not allowed.

OK. I understand "$^INPUT_LINE_NUMBER is not allowed".
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
On Fri, Jul 8, 2022 at 5:48 PM Paul "LeoNerd" Evans
<leonerd@leonerd.org.uk> wrote:
>
> On Fri, 10 Jun 2022 18:43:02 +0100
> "Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:
>
> > On Fri, 21 Jan 2022 15:05:23 +0000
> > "Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:
> >
> > > This seems like a fine idea and nobody's objected to it yet.
> > >
> > > Can you please write it up as a formal RFC on the usual process:
> > >
> > > https://github.com/Perl/RFCs/
> > >
> > > We have allocated the number 0014 for it.
> >
> > Hi Dan,
> >
> > A nudge to say we're out of the "5.36 release quiet time" now, so this
> > would be a good time to begin looking into this.
> >
> > Would you be able to write it up?
>
> Hi all,
>
> This has sat pending for a number of weeks now. We still think it's a
> good idea, but someone still has to write it up as a real RFC.
>
> A general request, to whomever is interested in having this as a
> feature, to have a go at writing this up. If it's still sitting after a
> few more weeks we'll call it "Parked" and stop considering it.

I've created an RFC for this: https://github.com/Perl/RFCs/pull/22
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
2022-7-11 20:42 Graham Knop <haarg@haarg.org> wrote:

>
> I've created an RFC for this: https://github.com/Perl/RFCs/pull/22


It looks good!.
Re: Pre-RFC: ${^ENGLISH_NAME} aliases for punctuation variables [ In reply to ]
On Fri, Oct 29, 2021, at 19:47, Dan Book wrote:
> Currently, each punctuation variable has an $ENGLISH_NAME alias available for readability. But this has a couple problems: it's only available if you "use English;" which does not provide a direct indication of the variables it's related to in the code, and was a significant performance penalty in older versions of Perl; these issues leading to not much use of the module and thus the knowledge of their existence has not become widespread; so average Perl programmers finding $CHILD_ERROR in Perl code are likely not to know it's an alias for $? or that it's a built-in variable at all, thus reducing its effective readability instead of increasing it.

This is in the RFC tracker at https://github.com/Perl/RFCs/pull/22 these days.

The blocker seemed to be the interaction between strict and these vars, since right now any ${^FOO} is permitted without declaration.


It sounds like the general consensus is that we can make "use strict 'vars'" affect this. So if you say `${^FOO}` and that's not one of Perl's global variables, it's fatal. We'll carve out an exception for FOO where FOO starts with an underscore.

Is that right?


--
rjbs