Skip Menu |
Report information
Id: 131965
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: david.warring <david.warring [at] gmail.com>
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



To: rakudobug [...] perl.org
Date: Sun, 27 Aug 2017 11:15:02 +1200
From: David Warring <david.warring [...] gmail.com>
Subject: Shaped arrays can't have zero size
Download (untitled) / with headers
text/plain 487b
This is OK:

% perl6 -e'my $size = 2; my @xref[$size,3] = ([1,2,3], [4,5,6]); say @xref'  
[[1 2 3] [4 5 6]]

But this isn't:

% perl6 -e'my $size = 0; my @xref[$size,3] = (); say @xref'                  
Illegal dimension in shape: 0. All dimensions must be integers bigger than 0
 in block <unit> at -e line 1

% perl6 -v
This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
implementing Perl 6.c.

Just seems an unreasonable restriction that the major shape size of an array can't be zero.
Indeed. The limit was introduced as a response to this ticket: https://rt.perl.org/Ticket/Display.html?id=126800
The check is probably too aggressive, and indeed, maybe there's nothing wrong with 0 sized arrays. I wonder what was the justification for making the check inclusive.
On 2017-08-26 16:15:33, david.warring wrote:
Show quoted text
> This is OK:
>
> % perl6 -e'my $size = 2; my @xref[$size,3] = ([1,2,3], [4,5,6]); say @xref'
>
> [[1 2 3] [4 5 6]]
>
> But this isn't:
>
> % perl6 -e'my $size = 0; my @xref[$size,3] = (); say @xref'
>
> Illegal dimension in shape: 0. All dimensions must be integers bigger than
> 0
> in block <unit> at -e line 1
>
> % perl6 -v
> This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
> implementing Perl 6.c.
>
> Just seems an unreasonable restriction that the major shape size of an
> array can't be zero.


To: Carl Mäsak via RT <perl6-bugs-followup [...] perl.org>
From: Brandon Allbery <allbery.b [...] gmail.com>
Subject: Re: [perl #131965] Shaped arrays can't have zero size
CC: David Warring <david.warring [...] gmail.com>
Date: Sat, 26 Aug 2017 20:12:45 -0400
Download (untitled) / with headers
text/plain 1.2k
How exactly do you index such an array?

On Sat, Aug 26, 2017 at 8:11 PM, Aleks-Daniel Jakimenko-Aleksejev via RT <perl6-bugs-followup@perl.org> wrote:
Show quoted text
Indeed. The limit was introduced as a response to this ticket:
https://rt.perl.org/Ticket/Display.html?id=126800
The check is probably too aggressive, and indeed, maybe there's nothing wrong
with 0 sized arrays. I wonder what was the justification for making the check
inclusive.
On 2017-08-26 16:15:33, david.warring wrote:
> This is OK:
>
> % perl6 -e'my $size = 2; my @xref[$size,3] = ([1,2,3], [4,5,6]); say @xref'
>
> [[1 2 3] [4 5 6]]
>
> But this isn't:
>
> % perl6 -e'my $size = 0; my @xref[$size,3] = (); say @xref'
>
> Illegal dimension in shape: 0. All dimensions must be integers bigger than
> 0
> in block <unit> at -e line 1
>
> % perl6 -v
> This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
> implementing Perl 6.c.
>
> Just seems an unreasonable restriction that the major shape size of an
> array can't be zero.




--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
Well, what do you mean? Of course you can't put anything into it, and any attempt to index it will throw. It may seem useless, however, if you can have an empty array, why can't you have a shaped empty array?
On 2017-08-26 17:13:02, allbery.b@gmail.com wrote:
Show quoted text
> How exactly do you index such an array?
>
> On Sat, Aug 26, 2017 at 8:11 PM, Aleks-Daniel Jakimenko-Aleksejev via RT <
> perl6-bugs-followup@perl.org> wrote:
>
> > Indeed. The limit was introduced as a response to this ticket:
> > https://rt.perl.org/Ticket/Display.html?id=126800
> > The check is probably too aggressive, and indeed, maybe there's nothing
> > wrong
> > with 0 sized arrays. I wonder what was the justification for making the
> > check
> > inclusive.
> > On 2017-08-26 16:15:33, david.warring wrote:
> > > This is OK:
> > >
> > > % perl6 -e'my $size = 2; my @xref[$size,3] = ([1,2,3], [4,5,6]); say
> > @xref'
> > >
> > > [[1 2 3] [4 5 6]]
> > >
> > > But this isn't:
> > >
> > > % perl6 -e'my $size = 0; my @xref[$size,3] = (); say @xref'
> > >
> > > Illegal dimension in shape: 0. All dimensions must be integers bigger
> > than
> > > 0
> > > in block <unit> at -e line 1
> > >
> > > % perl6 -v
> > > This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
> > > implementing Perl 6.c.
> > >
> > > Just seems an unreasonable restriction that the major shape size of an
> > > array can't be zero.
> >
> >
>
>


Date: Sat, 26 Aug 2017 20:38:29 -0400
CC: David Warring <david.warring [...] gmail.com>
Subject: Re: [perl #131965] Shaped arrays can't have zero size
From: Brandon Allbery <allbery.b [...] gmail.com>
To: Carl Mäsak via RT <perl6-bugs-followup [...] perl.org>
Download (untitled) / with headers
text/plain 548b

Show quoted text
Well, what do you mean? Of course you can't put anything into it, and any
attempt to index it will throw. It may seem useless, however, if you can have
an empty array, why can't you have a shaped empty array?

Only if all dimensions are unindexable. Otherwise you have something with inaccessible slots (and, potentially thereby, not truly leaked but unusable, memory).

And an empty unshaped array, in addition to being usable as such (degenerate case of all shaped dimensions being size 0), can be made non-empty. Shaped arrays cannot.

Subject: Re: [perl #131965] Shaped arrays can't have zero size
From: David Warring <david.warring [...] gmail.com>
Date: Mon, 28 Aug 2017 12:29:09 +1200
To: perl6-bugs-followup [...] perl.org
Download (untitled) / with headers
text/plain 1.2k
Attached is my use case which is parsing of PDF cross reference indices. There are normally three numeric entries per line. e.g.

xref
0 8
0000000000 65535 f
0000000009 00000 n
0000000074 00000 n
0000000120 00000 n

Which populates nicely into an array of 'n' lines of shape 3.

There's the rare, but possible case of an xref section with zero entries

xref
0 0

(I've encountered real-world PDF's like this).

The attached grammar/actions attempted to handle it as an array of shape [0;3],
but wont work on current Rakudo.

Just my preferred solution for the above case.
- David


On Sun, Aug 27, 2017 at 12:38 PM, Brandon Allbery via RT <perl6-bugs-followup@perl.org> wrote:
Show quoted text
> Well, what do you mean? Of course you can't put anything into it, and any
> attempt to index it will throw. It may seem useless, however, if you can
> have
> an empty array, why can't you have a shaped empty array?
>

Only if all dimensions are unindexable. Otherwise you have something with
inaccessible slots (and, potentially thereby, not truly leaked but
unusable, memory).

And an empty unshaped array, in addition to being usable as such
(degenerate case of all shaped dimensions being size 0), can be made
non-empty. Shaped arrays cannot.


Download Xref.pm
text/x-perl 1.3k

Message body is not shown because sender requested not to inline it.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org