Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

substr on compact array #3806

Closed
p6rt opened this issue May 3, 2015 · 7 comments
Closed

substr on compact array #3806

p6rt opened this issue May 3, 2015 · 7 comments

Comments

@p6rt
Copy link

p6rt commented May 3, 2015

Migrated from rt.perl.org#124455 (status was 'open')

Searchable as RT124455$

@p6rt
Copy link
Author

p6rt commented May 12, 2015

From @coke

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

1 similar comment
@p6rt
Copy link
Author

p6rt commented May 12, 2015

From @coke

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

@p6rt
Copy link
Author

p6rt commented Oct 2, 2017

From @AlexDaniel

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​:

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'

@p6rt
Copy link
Author

p6rt commented Oct 2, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Oct 2, 2017

From @timo

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.

@p6rt
Copy link
Author

p6rt commented Oct 2, 2017

From @timo

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.

@lizmat
Copy link
Contributor

lizmat commented Jan 17, 2020

Removing the tests and closing the ticket.

@lizmat lizmat closed this as completed Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants