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

Flattened list iteration #5819

Closed
p6rt opened this issue Nov 24, 2016 · 6 comments
Closed

Flattened list iteration #5819

p6rt opened this issue Nov 24, 2016 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Nov 24, 2016

Migrated from rt.perl.org#130160 (status was 'resolved')

Searchable as RT130160$

@p6rt
Copy link
Author

p6rt commented Nov 24, 2016

From tim.bollman@live.com

It appears that when iterating lazily through a list that's been flattened (the first time), sometimes certain elements are not reached. For background I was writing some code that used a trie, and was attempting to find the word "inclusive" out of input trigrams. I have cleared away as much of the surrounding code as I could to provide a minimal test case. If you enable the commented line (or otherwise iterate through the @​partials list at least once first), the output will be correct.

Thanks,
Tim Bollman

use v6;

sub find-words(@​partials) {
  state $output = '';
  # my @​a = @​partials.kv;
  for @​partials.kv -> $i, $word {
  my $backup = $output;
  $output ~= $word;
  take $output;
  find-words(@​partials[0 ..^ $i, $i ^..^ +@​partials].flat());
  $output = $backup;
  }
}

my @​found = gather find-words(<ive lus inc>);
.say for @​found;
# ive
# ivelus
# lus
# lusive
# lusiveinc
# lusinc
# lusincive
# inc
# incive

@p6rt
Copy link
Author

p6rt commented Nov 24, 2016

From tim.bollman@live.com

I've determined that the issue is the +@​partials. Sometimes that is returning 1 as the length of the list instead of the full list. It looks to be whenever the first index set returns the empty set, the size calculation fails.

________________________________
From​: perl6 via RT <perl6-bugs-followup@​perl.org>
Sent​: Wednesday, November 23, 2016 5​:15 PM
To​: tim.bollman@​live.com
Subject​: [perl #​130160] AutoReply​: [BUG] Flattened list iteration

Greetings,

This message has been automatically generated in response to the
creation of a trouble ticket regarding​:
  "[BUG] Flattened list iteration",
a summary of which appears below.

There is no need to reply to this message right now. Your ticket has been
assigned an ID of [perl #​130160].

Please include the string​:

  [perl #​130160]

in the subject line of all future correspondence about this issue. To do so,
you may reply to this message.

  Thank you,
  perl6-bugs-followup@​perl.org


It appears that when iterating lazily through a list that's been flattened (the first time), sometimes certain elements are not reached. For background I was writing some code that used a trie, and was attempting to find the word "inclusive" out of input trigrams. I have cleared away as much of the surrounding code as I could to provide a minimal test case. If you enable the commented line (or otherwise iterate through the @​partials list at least once first), the output will be correct.

Thanks,
Tim Bollman

use v6;

sub find-words(@​partials) {
  state $output = '';
  # my @​a = @​partials.kv;
  for @​partials.kv -> $i, $word {
  my $backup = $output;
  $output ~= $word;
  take $output;
  find-words(@​partials[0 ..^ $i, $i ^..^ +@​partials].flat());
  $output = $backup;
  }
}

my @​found = gather find-words(<ive lus inc>);
.say for @​found;
# ive
# ivelus
# lus
# lusive
# lusiveinc
# lusinc
# lusincive
# inc
# incive

@p6rt
Copy link
Author

p6rt commented Nov 24, 2016

From lucasbuchala@gmail.com

I found this results that may be related to this issue.
Maybe there's some strange interaction between these List methods?

  > my @​a := <a b c>[0..2, 0..2].flat.cache; say @​a
  (a b c a b c)

  > my @​a := <a b c>[0..2, 0..2].flat.cache; @​a.Bool; @​a.elems; say @​a
  (a a b c)

  > my @​a := <a b c>[0..2, 0..2].flat.cache; @​a.eager; @​a.Bool; @​a.elems; say @​a
  (a b c a b c)

@p6rt
Copy link
Author

p6rt commented Nov 24, 2016

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

@p6rt
Copy link
Author

p6rt commented Nov 24, 2016

From @zoffixznet

On Wed, 23 Nov 2016 17​:15​:41 -0800, TimTom wrote​:

It appears that when iterating lazily through a list that's been
flattened (the first time), sometimes certain elements are not
reached.

Thanks for the report.

Fixed in rakudo/rakudo@61a18c0
Tests added in Raku/roast@10f39438be

@p6rt
Copy link
Author

p6rt commented Nov 24, 2016

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Nov 24, 2016
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant