Skip to content

Instantly share code, notes, and snippets.

@cognominal
Last active March 25, 2021 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cognominal/5458754 to your computer and use it in GitHub Desktop.
Save cognominal/5458754 to your computer and use it in GitHub Desktop.
Problem is \:get_attr_str() not implemented in class 'Coroutine'current instr.: 'print_exception' pc 111585 (src/gen/CORE.setting.pir:50152) (src/gen/CORE.setting:9760) #raku
# We recursively.generate permutations
# Here is one step of the recursion :
# Given a array @l, $e is its first element and @m the array @l minus $e. We
# get the permutations of @l by getting all the permutations of @m. For each
# such permutation, we alternatively insert $e in each possible position obtaining
# @m+1 arrays.
sub permutations(*@l is copy) {
gather {
if @l == 1 {
take @l;
} else {
while (my $e = @l.shift) {
# say "=@l[]";
# say $e;
for permutations(@l) -> @p {
for 0..@p {
my @r = @p;
@r.splice: $_, 0, $e;
# say "?@r[]";
take @r;
}
}
}
}
}
}
my @a = permutations 1;
say "done: @a[]";
@a = permutations 1..4;
say "done: @a[]";
=begin END
proto sub fact($i) { ... }
multi sub fact(0) { 1 }
multi suv fact($n) { $n * fact($n-1)}
+uniq permutations(5) == fact 5
@cognominal
Copy link
Author

the problem was solved by moving the return outside the gather.
thx @jnthn.
the program is not yet correct.
I will submit the correct program as a pullt request to the rakudo repository

@cognominal
Copy link
Author

In the new version, I am stuck again with the same problem

@cognominal
Copy link
Author

I may have hit a limit of the current implementaton
[14:54] cognominal: iirc [Coke] has hit another limitation of gather/take recentely; if you reuse the same gather/take block, the first iterator has to be exhausted before the second one is started

see http://irclog.perlgeek.de/perl6/2013-04-25#i_6745999

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment