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

Owner: Nobody
Requestors: davidnmfarrell [at] gmail.com
Cc:
AdminCc:

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



RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 831b
3 tests here that need fixing or review: my uint8 @buffer = ('A' .. 'Z').map({ .ord }); is(substr(@buffer, 0, 8), ord('A'), 'substr on compact array (1)'); is(substr(@buffer, 200, 8), ord('Z'), 'substr on compact array (2)'); is( substr(@buffer, 0, 16), sprintf('%08d%08d', ord('A'), ord('B')), 'substr on compacy array (3)' ); yields: # Failed test 'substr on compact array (1)' # at t/spec/S02-types/compact.rakudo.moar line 14 # expected: '65' # got: '65 66 67' # Failed test 'substr on compact array (2)' # at t/spec/S02-types/compact.rakudo.moar line 15 # expected: '90' # got: (Failure) # Failed test 'substr on compacy array (3)' # at t/spec/S02-types/compact.rakudo.moar line 16 # expected: '0000006500000066' # got: '65 66 67 68 69 7' -- Will "Coke" Coleda
Oh wow, that's really interesting… and old.

I don't think that substr should work like this. Normal arrays are stringified by 「substr」, why would it do something completely different for a native array? So for both UInt and uint8 arrays I'd expect “65 66 67” as an output.

I think this ticket is rejectable as soon as someone can justify it better than me.

On 2015-05-12 09:54:38, coke wrote:
Show quoted text
> 3 tests here that need fixing or review:
>
> my uint8 @buffer = ('A' .. 'Z').map({ .ord });
> is(substr(@buffer, 0, 8), ord('A'), 'substr on compact array (1)');
> is(substr(@buffer, 200, 8), ord('Z'), 'substr on compact array (2)');
> is(
> substr(@buffer, 0, 16),
> sprintf('%08d%08d', ord('A'), ord('B')),
> 'substr on compacy array (3)'
> );
>
> yields:
>
> # Failed test 'substr on compact array (1)'
> # at t/spec/S02-types/compact.rakudo.moar line 14
> # expected: '65'
> # got: '65 66 67'
> # Failed test 'substr on compact array (2)'
> # at t/spec/S02-types/compact.rakudo.moar line 15
> # expected: '90'
> # got: (Failure)
> # Failed test 'substr on compacy array (3)'
> # at t/spec/S02-types/compact.rakudo.moar line 16
> # expected: '0000006500000066'
> # got: '65 66 67 68 69 7'


Download (untitled) / with headers
text/plain 346b
The tests are bogus just the assumption that a substr of length 8 will give you 8 bits rather than 8 bytes, that's already wildly inconsistent with what substr does otherwise. really this code looks like the desire to have `vec` from perl5 implemented in perl6 by re-using the substr name. I think it's the wrong peg to hang this feature off of.
Download (untitled) / with headers
text/plain 117b
Also, the design docs say you get the same kind of buffer back from substr on a buf, but we have subbuf for that now.


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