Mailing List Archive

ban empty sorts for 5.36 to free the colon?
I propose that a sort with no physical arguments should be made
a compile-time error for 5.36:

@a = sort; # currently equivalent to @a = (); would become compile error

@empty = (); @a = sort @empty # unaffected

I suspect that this usage is exceedingly rare in real code, and if present
represents a thinko.

The advantage of making it a compile-time error (and thus flushing out any
remaining uses of it) is that it then allows for the possibility at some
future time of adding an attribute-like syntax to sort.

At the moment, in:

@a = $cond ? sort : ....;

the colon is interpreted as part of the ternary conditional operator. I
would like to open up the possibility in the future of the colon being
interpreted instead as part of the sort syntax, introducing some sort of
attribute. For example (hypothetically):

sort :num 4,3,5;

says to sort numerically. Or perhaps to introduce an inline sub:

sort :sub ($x,$y) { $x <= $y } 4,3,5

or whatever.

The important thing is that I don't want to start a long discussion (yet)
about HOW the new syntax could be used; I just want to get quick agreement
that by banning empty sorts ASAP we free up the syntax space for use in a
few releases' time.

--
My Dad used to say 'always fight fire with fire', which is probably why
he got thrown out of the fire brigade.
Re: ban empty sorts for 5.36 to free the colon? [ In reply to ]
I support your proposal. -- Darren Duncan

On 2022-01-17 3:34 a.m., Dave Mitchell wrote:
> I propose that a sort with no physical arguments should be made
> a compile-time error for 5.36:
>
> @a = sort; # currently equivalent to @a = (); would become compile error
>
> @empty = (); @a = sort @empty # unaffected
>
> I suspect that this usage is exceedingly rare in real code, and if present
> represents a thinko.
>
> The advantage of making it a compile-time error (and thus flushing out any
> remaining uses of it) is that it then allows for the possibility at some
> future time of adding an attribute-like syntax to sort.
>
> At the moment, in:
>
> @a = $cond ? sort : ....;
>
> the colon is interpreted as part of the ternary conditional operator. I
> would like to open up the possibility in the future of the colon being
> interpreted instead as part of the sort syntax, introducing some sort of
> attribute. For example (hypothetically):
>
> sort :num 4,3,5;
>
> says to sort numerically. Or perhaps to introduce an inline sub:
>
> sort :sub ($x,$y) { $x <= $y } 4,3,5
>
> or whatever.
>
> The important thing is that I don't want to start a long discussion (yet)
> about HOW the new syntax could be used; I just want to get quick agreement
> that by banning empty sorts ASAP we free up the syntax space for use in a
> few releases' time.
>
Re: ban empty sorts for 5.36 to free the colon? [ In reply to ]
On Mon, 17 Jan 2022 11:34:40 +0000
Dave Mitchell <davem@iabyn.com> wrote:

> I propose that a sort with no physical arguments should be made
> a compile-time error for 5.36:
>
> @a = sort; # currently equivalent to @a = (); would become
> compile error
>
> @empty = (); @a = sort @empty # unaffected
...
> The important thing is that I don't want to start a long discussion
> (yet) about HOW the new syntax could be used; I just want to get
> quick agreement that by banning empty sorts ASAP we free up the
> syntax space for use in a few releases' time.

Sounds good, +1 from me.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: ban empty sorts for 5.36 to free the colon? [ In reply to ]
On Mon, 17 Jan 2022 11:34:40 +0000, Dave Mitchell <davem@iabyn.com> wrote:

> I propose that a sort with no physical arguments should be made
> a compile-time error for 5.36:
>
> @a = sort; # currently equivalent to @a = (); would become compile error
>
> @empty = (); @a = sort @empty # unaffected
>
> I suspect that this usage is exceedingly rare in real code, and if present
> represents a thinko.
>
> The advantage of making it a compile-time error (and thus flushing out any
> remaining uses of it) is that it then allows for the possibility at some
> future time of adding an attribute-like syntax to sort.
>
> At the moment, in:
>
> @a = $cond ? sort : ....;
>
> the colon is interpreted as part of the ternary conditional operator. I
> would like to open up the possibility in the future of the colon being
> interpreted instead as part of the sort syntax, introducing some sort of
> attribute. For example (hypothetically):
>
> sort :num 4,3,5;
>
> says to sort numerically. Or perhaps to introduce an inline sub:
>
> sort :sub ($x,$y) { $x <= $y } 4,3,5
>
> or whatever.
>
> The important thing is that I don't want to start a long discussion (yet)
> about HOW the new syntax could be used; I just want to get quick agreement
> that by banning empty sorts ASAP we free up the syntax space for use in a
> few releases' time.

I do not see any negative impact of this proposal, so I support it

--
H.Merijn Brand https://tux.nl Perl Monger http://amsterdam.pm.org/
using perl5.00307 .. 5.33 porting perl5 on HP-UX, AIX, and Linux
https://tux.nl/email.html http://qa.perl.org https://www.test-smoke.org
Re: ban empty sorts for 5.36 to free the colon? [ In reply to ]
On Mon, Jan 17, 2022, at 6:34 AM, Dave Mitchell wrote:
> I propose that a sort with no physical arguments should be made
> a compile-time error for 5.36:

Sounds fine to me.

--
rjbs
Re: ban empty sorts for 5.36 to free the colon? [ In reply to ]
On Mon, Jan 17, 2022 at 11:34:40AM +0000, Dave Mitchell wrote:
> I propose that a sort with no physical arguments should be made
> a compile-time error for 5.36:
>
> @a = sort; # currently equivalent to @a = (); would become compile error
>
> @empty = (); @a = sort @empty # unaffected

Now done as v5.35.7-56-g78cc98885f
(and I even remembered to add a perldelta entry!)

--
Never work with children, animals, or actors.